1013 Counterfeit Dollar

直接枚举哪个重/轻即可

  1. //4386918_AC_0MS_440K
  2. /**********************************************************************
  3. *       Online Judge   : POJ
  4. *       Problem Title  : Counterfeit Dollar
  5. *       ID             : 1013
  6. *       Date           : 11/17/2008
  7. *       Time           : 21:19:25
  8. *       Computer Name  : EVERLASTING-PC
  9. ***********************************************************************/
  10. #include<iostream>
  11. #include<string>
  12. using namespace std;
  13. int n;
  14. string s[3][3];
  15. bool Fit(int diff,char ch)
  16. {
  17.     for(int i=0;i<3;++i)
  18.     {
  19.         if((s[i][2]!="even")&&(s[i][0].find(ch)==-1)&&(s[i][1].find(ch)==-1))
  20.         {
  21.             return false;
  22.         }
  23.         if((s[i][2]=="even")&&((s[i][0].find(ch)!=-1)||(s[i][1].find(ch)!=-1)))
  24.         {
  25.             return false;
  26.         }
  27.         if((diff==0)&&(s[i][0].find(ch)!=-1)&&(s[i][2]=="down"))
  28.         {
  29.             return false;
  30.         }
  31.         if((diff==0)&&(s[i][1].find(ch)!=-1)&&(s[i][2]=="up"))
  32.         {
  33.             return false;
  34.         }
  35.         if((diff==1)&&(s[i][0].find(ch)!=-1)&&(s[i][2]=="up"))
  36.         {
  37.             return false;
  38.         }
  39.         if((diff==1)&&(s[i][1].find(ch)!=-1)&&(s[i][2]=="down"))
  40.         {
  41.             return false;
  42.         }
  43.     }
  44.     return true;
  45. }
  46. void Solve()
  47. {
  48.     for(int diff=0;diff<=1;++diff)
  49.     {
  50.         for(char ch='A';ch<='L';++ch)
  51.         {
  52.             if(Fit(diff,ch))
  53.             {
  54.                 cout<<ch<<" is the counterfeit coin and it is "<<(diff==0?"heavy":"light")<<"./n";
  55.                 return;
  56.             }
  57.         }
  58.     }   
  59. }
  60. int main()
  61. {
  62.     //freopen("in_1013.txt","r",stdin);
  63.     cin>>n;
  64.     while(n--)
  65.     {
  66.         for(int i=0;i<3;++i)
  67.             for(int j=0;j<3;++j)
  68.                 cin>>s[i][j];
  69.         Solve();
  70.     }
  71.     return 0;
  72. }

你可能感兴趣的:(1013 Counterfeit Dollar)