public class People { private int age; public int Age { get { return age; } set { age = value; } } private string status; public string Status { get { return status; } set { status = value; } } private int no; public int No { get { return no; } set { no = value; } } public People(int nowNo, string info) { no = nowNo; string[] s = info.Split('|'); status = s[0]; age = int.Parse(s[1]); } public void FindChildren() { int minAge = 100; List<People> l = new List<People>(); for (int i = 0; i < 18; i++) { People p = new People(Check(i)); if (p.Status.Equals("儿童")) { if (p.Age < minAge) { l.Clear(); l.Add(p); } else if (p.Age = minAge) { l.Add(p); } } } if (l.Count == 0) return; if (l.Count == 1) Gift( l[0].No); if (l.Count > 1) { Random r = new Random(); Gift( r.Next(0, l.Count)); } } }
最后那个 if (l.Count > 1) { Random r = new Random(); Gift( l[r.Next(0, l.Count)].No); }
using System; using System.Collections.Generic; using System.Text;namespace ConsoleApplication21 { class Program { class Man { public int _Locid; public String Style; public int Age; public Man(int _Locid, String Style, int Age) { this._Locid = _Locid; this.Style = Style; this.Age = Age; } } static List<Man> Men = new List<Man>(); static Man Result = null; static void Main(string[] args) { Men.Add(new Man(1, "老人", 80)); Men.Add(new Man(2, "小孩", 5)); Men.Add(new Man(3, "小孩", 4)); Men.Add(new Man(4, "小孩", 7)); Men.Add(new Man(5, "青年", 23)); Men.Add(new Man(6, "小孩", 4)); Men.ForEach(delegate(Man M) { if (Result == null || M.Age < Result.Age || M.Age == Result.Age && new Random().Next(2) == 1) Result = M; }); Gift(Result); Console.Read(); } static void Gift(Man M) { Console.WriteLine(M._Locid + " " + M.Style + " " + M.Age + " 获得礼物"); } } }
{
private int age; public int Age
{
get { return age; }
set { age = value; }
} private string status; public string Status
{
get { return status; }
set { status = value; }
} private int no; public int No
{
get { return no; }
set { no = value; }
}
public People(int nowNo, string info)
{
no = nowNo;
string[] s = info.Split('|');
status = s[0];
age = int.Parse(s[1]);
} public void FindChildren()
{
int minAge = 100;
List<People> l = new List<People>();
for (int i = 0; i < 18; i++)
{
People p = new People(Check(i));
if (p.Status.Equals("儿童"))
{
if (p.Age < minAge)
{
l.Clear();
l.Add(p);
}
else if (p.Age = minAge)
{
l.Add(p);
}
}
} if (l.Count == 0)
return;
if (l.Count == 1)
Gift( l[0].No);
if (l.Count > 1)
{
Random r = new Random();
Gift( r.Next(0, l.Count));
}
}
}
{
Random r = new Random();
Gift( l[r.Next(0, l.Count)].No);
}
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication21
{
class Program
{
class Man
{
public int _Locid;
public String Style;
public int Age; public Man(int _Locid, String Style, int Age)
{
this._Locid = _Locid;
this.Style = Style;
this.Age = Age;
}
} static List<Man> Men = new List<Man>();
static Man Result = null; static void Main(string[] args)
{
Men.Add(new Man(1, "老人", 80));
Men.Add(new Man(2, "小孩", 5));
Men.Add(new Man(3, "小孩", 4));
Men.Add(new Man(4, "小孩", 7));
Men.Add(new Man(5, "青年", 23));
Men.Add(new Man(6, "小孩", 4)); Men.ForEach(delegate(Man M)
{
if (Result == null || M.Age < Result.Age || M.Age == Result.Age && new Random().Next(2) == 1)
Result = M;
});
Gift(Result);
Console.Read();
} static void Gift(Man M)
{
Console.WriteLine(M._Locid + " " + M.Style + " " + M.Age + " 获得礼物");
}
}
}