小编Mai*_*min的帖子

你如何计算从1到99,999,999(1亿的1短)的发生率,总计有1到1的数量

我开始学习c#并完成这项任务.我已经这样做了这是代码:

string y = "";
int count = 0;
string x  = "";
string[] arr = new string[100000000];

for (int i = 0; i < 100000000; i++)
{ 
    x = i.ToString() + x;
}

Console.WriteLine(x);

for (int j = 0; j < x.Length; j++)
{
    y = x.Substring(j, 1);

    switch (y)
    {
        case "1":
             count ++;
             break;

        default:
            break;
    } 
}

Console.WriteLine(count);
Run Code Online (Sandbox Code Playgroud)

代码在小范围(0到1000)的情况下正常工作但在运行它的范围为1亿时它不会产生任何结果(我等待但没有输出)加上看起来我的代码不是有效的方式.我现在的问题是这个代码中的问题是什么,以及是否有更好的解决方案来完成这项任务.

c#

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

标签 统计

c# ×1