Ray's playground

 

POJ 1013

code
  1 #include <iostream>
  2 #include <string>
  3 using namespace std;
  4 
  5 int main()
  6 {
  7     int count;
  8 
  9     cin >> count;
 10     while(count > 0)
 11     {
 12         count--;
 13         bool real[12= {0};
 14         int heavy[12= {0};
 15         int light[12= {0};
 16         int j;
 17         for(int k=0; k<3; k++)
 18         {
 19             string left, right, result;
 20             cin >> left >> right >> result;
 21             if(result == "even")
 22             {
 23                 for(j=0; j<left.size(); j++)
 24                 {
 25                     real[left[j] - 'A'= true;
 26                     real[right[j] - 'A'= true;
 27                 }
 28             }
 29             else if(result == "up")
 30             {
 31                 for(j=0; j<left.size(); j++)
 32                 {
 33                     heavy[left[j] - 'A']++;
 34                     light[right[j] - 'A']++;
 35                 }
 36             }
 37             else if(result == "down")
 38             {
 39                 for(j=0; j<left.size(); j++)
 40                 {
 41                     light[left[j] - 'A']++;
 42                     heavy[right[j] - 'A']++;
 43                 }
 44             }
 45         }
 46 
 47         int heavyorlight = 0;
 48         char max = 'A';
 49         for(int i='A'; i<'M'; i++)
 50         {
 51             if(real[i-'A'])
 52             {
 53                 continue;
 54             }
 55             int temp = 0;
 56 
 57             if(light[i-'A'> 0 && heavy[i-'A'== 0)
 58             {
 59                 if(heavyorlight == 1)
 60                 {
 61                     temp = light[max-'A'];
 62                 }
 63                 else if(heavyorlight == 2)
 64                 {
 65                     temp = heavy[max-'A'];
 66                 }
 67 
 68                 if(light[i-'A'> temp)
 69                 {
 70                     heavyorlight = 1;
 71                     max = i;
 72                 }
 73                 continue;
 74             }
 75 
 76             if(light[i-'A'== 0 && heavy[i-'A'> 0)
 77             {
 78                 if(heavyorlight == 1)
 79                 {
 80                     temp = light[max-'A'];
 81                 }
 82                 else if(heavyorlight == 2)
 83                 {
 84                     temp = heavy[max-'A'];
 85                 }
 86 
 87                 if(heavy[i-'A'> temp)
 88                 {
 89                     heavyorlight = 2;
 90                     max = i;
 91                 }
 92                 continue;
 93             }
 94         }
 95 
 96         if(heavyorlight == 1)
 97         {
 98             cout << max << " is the counterfeit coin and it is light." << endl; 
 99         }
100         else
101         {
102             cout << max << " is the counterfeit coin and it is heavy." << endl; 
103         }
104     }
105 
106     return 0;
107 }

 

posted on 2010-08-18 22:09  Ray Z  阅读(377)  评论(0编辑  收藏  举报

导航