比方说输入一组数据 “123 45166 7849” 如何让他们用空格隔开的方式加在一起,然后低于20的删除。就像最后就是“22,28 ” (4加5加1加6加6得22)
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string[] str1 = str.Split(' ');
string sum = "";
for (int i = 0; i < str1.Length; i++)
{
char[] c = str1[i].ToArray();
int num = 0;
for (int j = 0; j < c.Length; j++)
{
num += Convert.ToInt32(c[j].ToString());
}
if (num >= 20)
{
sum += num.ToString() + ",";
num = 0;
}
}
sum = sum.Substring(0, sum.Length - 1);
Console.WriteLine(sum);
Console.ReadLine();//打断点
}
}