我们有一个输入字符串,例如“456,678,4599,87567” 需要找到逗号分隔数字的平均数大于数字x的数字的计数。 下面是该我工作的程序problem.wanted知道如果任何人可以使用C#代码计算平均值大于x的数字的计数
public static int test(string i2,int limit)
{
int count=0;
int i;
int len = 0;
Int32 sum;
char[] tm={'{','}'};
i2 = i2.Trim(tm);
string[] w = i2.Split(',');
len = w.Length;
while (len-- > 0)
{
i=0;
sum = 0;
while (i < w[len].Length)
{
sum += w[len][i] - '0';
i++;
}
if (sum/i >= limit)
count++;
}
return count;
}
五个问题,都或多或少相同。 – Abizern 2011-12-28 20:22:32