using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace odds
{
class Program
{
static void Main(string[] args)
{
List<string> str = new List<string>();
int len = 0;
int jsum =0;
int osum =0;
Console.WriteLine("输出数组的元素,以q结束");
while (true)
{
string input = Console.ReadLine();
if (input.Equals("q") == false) //如果输入的不是q(区分大小写),则增加记录
str.Insert(len++, input);
else
break;
}
//Console.WriteLine("输出数据长度");
// Console.WriteLine(len); //结果说明数据是按行存在链表中的,每行占链表一个值
// Console.WriteLine("依次输出链表中数据");
// for (int i = 0; i < len; i++)
// {
// Console.WriteLine(str[i]); //依次输出链表每个值,也是依次输出每行
//}
//Console.WriteLine("依次输出每个值");
string[][] every = new string[len][]; //交叉数组,行固定,为上面得到的行数,每一行的长度不定(每行字符间以空格或其他分割)
for (int i = 0; i < len; i++)
{
every[i] = str[i].Split(); //C#对空格的分割方式之一,如果是其他分割方式,就需要也使用上面的链表分割每行的方式了
}
//for (int i = 0; i < len; i++)
//{
// for (int j = 0; j < every[i].Length; j++)
// {
// Console.WriteLine(every[i][j]);
// }
// }
for (int i = 0; i < len; i++)
{
for (int j = 0; j < every[i].Length; j++)
{
int aa;
// Console.WriteLine(every[i][j]);
aa = int.Parse(every[i][j]);
if ((aa % 2) == 1)
{
jsum += aa;
}
else {
osum += aa;
}
}
}
Console.WriteLine("奇数之和为:");
Console.WriteLine(jsum);
Console.WriteLine("偶数之和为:");
Console.WriteLine(osum);
Console.ReadKey();
}
}
}
![]()