superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ZOJ 1184 - Counterfeit Dollar

Posted on 2008-04-23 20:38 superman 阅读(282) 评论(0)  编辑 收藏 引用 所属分类: ZOJ
 1 /* Accepted 1184 C++ 00:00.00 832K */
 2 #include <string>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9      int n;
10      cin >> n;
11      while(n--)
12      {
13           string left, right, status;
14           
15           int weight[12= {0};
16           bool real[12= {false};
17           
18           for(int i = 0; i < 3; i++)
19           {
20                cin >> left >> right >> status;
21                if(status == "even")
22                {
23                     for(int j = 0; j < left.size(); j++)
24                          real[left[j] - 'A'= true, real[right[j] - 'A'= true;
25                     continue;
26                }
27                if(status == "up")
28                {
29                     for(int j = 0; j < left.size(); j++)
30                          weight[left[j] - 'A']++, weight[right[j] - 'A']--;
31                     continue;
32                }
33                //status == "down"
34                for(int j = 0; j < left.size(); j++)
35                     weight[left[j] - 'A']--, weight[right[j] - 'A']++;
36           }
37           
38           int max = 0, counterfeit; bool light;
39           for(int i = 0; i < 12; i++)
40                if(real[i] == false)
41                     if(max < abs(weight[i]))
42                     {
43                          max = abs(weight[i]);
44                          counterfeit = i;
45                          if(weight[i] < 0)
46                               light = true;
47                          else
48                               light = false;
49                     }
50           cout << char(counterfeit + 'A'<< " is the counterfeit coin and it is "
51                << (light ? "light." : "heavy."<< endl;
52      }
53      
54      return 0;
55 }
56 

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理