111,125
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
namespace CSharp
{
class mark
{
public char code;
public List<int> list = new List<int>();
public mark(char ch, params int[] _list)
{
code = ch;
for (int i = 0; i < _list.Length; i++)
{
list.Add(_list[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
List<mark> mm = new List<mark>();
mm.Add(new mark('a', 0, 0, 0));
mm.Add(new mark('b', 1, 1));
foreach (mark m in mm)
{
if (m.list.IndexOf(1) == m.list.LastIndexOf(1)) //only 1 or none
{
if (m.list.IndexOf(1) == -1) // none
{
m.list.Add(1);
}
}
else //more than 1
{
m.list.RemoveAll(delegate(int i)
{
return i == 1;
});
m.list.Add(1);
}
//output
Console.Write("{0} : ", m.code);
foreach (int i in m.list)
Console.Write(i);
Console.WriteLine();
}
}
}
}