poj1013

      Referring to problem-solving ideas of others, approximately every coin has two elements, whether as a true currency, a degree of suspicion as being counterfeit. Initial are all counterfeit money, and the degree of suspicion is 0. When the sides are equal it can be determined as genuine, when the light is not equal to the degree of suspicion minus one side, here the degree of suspicion weight plus one, when the last is not determined as genuine and counterfeit, compared with the maximum degree of suspicion, and then the degree of suspicion of its negative determination is lighter or heavier.

#include <the iostream>
the using namespace STD;
typedef struct COIN
{
    int Degree;
    BOOL BL;
} COIN; // two elements of the structure of the coin deposit
void lessen (coin c [], int n, string s) // cast doubts -
{
    for (int I = 0; I <n-; I ++)
    {
        int int = A (S [I]) - 65; // int letters into its position over the array structure multiple 65
        C [A] .degree -;
    }
}
void Increase (COIN C [], int n-, String S) // extent suspected ++
{
    for (int I = 0; I <n-; I ++)
    {
        int int = A (S [I]) -65;
        ; C [A] .degree ++
    }
}
int main (void)
{
    String S1, S2, S3;
    int Cases;
    int max;
    CIN >> Cases;
    while(cases)
    {
        coin c[13];
        for(int i=0;i<13;i++)
        {
          c[i].degree=0;
          c[i].bl=false;
        }//初始化全为假币且怀疑程度为0
        max=12;
        for(int i=0;i<3;i++)//三次称量
        {
            cin>>s1>>s2>>s3;
        if(s3=="up")
        {
            increase(c,s1.size(),s1);
            lessen(c,s2.size(),s2);
        }
        else if(s3=="even")
        {
            for(int i=0;i<s1.size();i++)
             {
                int a=int(s1[i])-65;
                int b=int(s2[i])-65;
                c[a].bl=true;
                c[b].bl=true;
             }
        }
        else
        {
            lessen(c,s1.size(),s1);
            increase(c,s2.size(),s2);
        }
        }
        for(int i=0;i<12;i++)
       {
          if(c[i].degree*c[i].degree>c[max].degree*c[max].degree&&!c[i].bl)
            max=i;
       }
      if(c[max].degree<0) cout<<char(max+65)<<" is the counterfeit coin and it is light."<<endl;
      else cout<<char(max+65)<<" is the counterfeit coin and it is heavy."<<endl;
        cases--;
    }
    return 0;
}

发布了20 篇原创文章 · 获赞 3 · 访问量 5482

Guess you like

Origin blog.csdn.net/treble_csnd/article/details/79297622