小编Mil*_*orn的帖子

Idiomatic way to Concat Leading Zeros in Go

I came up with a way to pad leading zeros into a Go string. I'm not sure if this is the way you do this in Go. Is there a proper way to do this in Go? This is what I came up with and can be found inside the second if block. I tried Google to see if it had something built in without luck.

func integerToStringOfFixedWidth(n int, w int) string {
  s := strconv.Itoa(n)
  l := len(s)

  if …
Run Code Online (Sandbox Code Playgroud)

idiomatic go leading-zero

1
推荐指数
1
解决办法
78
查看次数

在 C# 中反转字符串中的元音

我试图将一个字符串作为输入并返回只有元音反转的字符串。它没有错误,但不是没有错误。它在Test19()Test20 上失败。没有想法如何解决这个问题或为什么我在这个测试中遇到问题。所有其他测试通过。第一个代码块是我的代码,然后是我在第二个块中创建的测试。

这是该页面的链接,其中详细介绍了我所做的测试的更多信息。 Nunit.org StringAssert (NUnit 2.2.3)

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vowels
{
    public class reverseVowels
    {
        public static bool IsVowel(char c)
        {
            char[] vowels = new[] { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
            return vowels.Any(ch => ch == c);
        }

        public static string reverseVowelsOfString(string s)
        {
            List<char> list = (from char c in s
                               where IsVowel(c)
                               select c).ToList();
            StringBuilder sb = new StringBuilder();

            foreach (char v in …
Run Code Online (Sandbox Code Playgroud)

c# linq stringbuilder nunit list

1
推荐指数
1
解决办法
215
查看次数

c++ 没有合适的构造函数可以将“int”转换为“std::pair&lt;int, int&gt;”

我无法解决此错误。当我搜索此错误时,我在 Google 上没有任何运气。

没有合适的构造函数可以将“int”转换为“std::pair<int, int>”

#include <utility>

using namespace std;

pair<int, int> solve(int s, int g)
{
    return s % g != 0 ? (-1, -1) : (g, s - g);
}
Run Code Online (Sandbox Code Playgroud)

错误波浪线位于它正在检查的返回中的第一个s下...

s % g != 0

我不知道如何解决这个问题。在 C# 中,这会起作用。

public static (int, int) solve(int s, int g) => s % g != 0 ? (-1, -1) : (g, s - g);
Run Code Online (Sandbox Code Playgroud)

c++ std-pair

0
推荐指数
1
解决办法
270
查看次数

标签 统计

c# ×1

c++ ×1

go ×1

idiomatic ×1

leading-zero ×1

linq ×1

list ×1

nunit ×1

std-pair ×1

stringbuilder ×1