码迷,mamicode.com
首页 > 其他好文 > 详细

研究人员参加比赛判断

时间:2015-05-13 18:29:09      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

Q:A1 A2 A3 A4 A5五名研究人员有可能报名化学比赛,根据下列条件判断那些人参加了比赛:

1. A1参加时,A2也参加;

2. A2和A3只有一个人参加;

3. A3和A4或者都参加,或者都不参加;

4. A4和A5中至少有一个人参加;

5. 如果A5参加,那么A1和A4也都参加。

Write your C# code to programmatically calculate the result:

 1 class people {
 2         public people() {}
 3         private int[] a = new int[6];
 4 
 5         public int A1
 6         {
 7             get { return a[1]; }
 8             set
 9             {
10                 a[1] = value;
11                 if (a[1] == 1) A2 = 1;
12                 Console.WriteLine("A1:"+a[1]);
13             }
14         }
15         public int A2
16         {
17             get { return a[2]; }
18             set
19             {
20                 a[2] = value;
21                 if(A3==a[2]) A3 = a[2] == 1 ? 0 : 1;
22                 Console.WriteLine("A2:" + a[2]);
23             }
24         }
25         public int A3
26         {
27             get { return a[3]; }
28             set
29             {
30                 a[3] = value;
31                 if(A4!=a[3]) A4 = a[3];
32                 if (A2 == a[3]) A2 = a[3] == 1 ? 0 : 1;
33                 Console.WriteLine("A3:" + a[3]);
34             }
35         }
36         public int A4
37         {
38             get { return a[4]; }
39             set
40             {
41                 a[4] = value;
42                 if (A5 == 0) a[4] = 1;
43                 if (A3 != a[4]) A3 = a[4];
44                 Console.WriteLine("A4:" + a[4]);
45             }
46         }
47         public int A5
48         {
49             get { return a[5]; }
50             set
51             {
52                 a[5] = value;
53                 if (a[5] == 1)
54                 {
55                     A4 = 1;
56                     A1 = 1;
57                 }
58 
59                 Console.WriteLine("A5:" + a[5]);
60             }
61         }
62     }
63     class Program
64     {
65         static void Main(string[] args)
66         {
67             people ps = new people();
68             ps.A1 = ps.A2 = ps.A3 = ps.A4 = ps.A5 = 0;
69             Console.Write("THIS IS:"+ps.A1+","+ps.A2+","+ps.A3+","+ps.A4+","+ps.A5);
70             Console.ReadLine();
71         }
72     }

求指教

研究人员参加比赛判断

标签:

原文地址:http://www.cnblogs.com/janey-Tang/p/4500733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!