hdu 1482

来源:互联网 发布:手机淘宝卖家中心 编辑:程序博客网 时间:2024/06/10 09:35

http://acm.hdu.edu.cn/showproblem.php?pid=1482

首先要明白,给出的数据一定能找出假币。even表明两边都是真币。真要不是even,那么两边出现的币里一定有假币,假币造成的轻重影响可用正负表示。所以用一个数组记录一定为真的货币,一个数组记录影响,由于每次两边的变化不同,所以要用两个数组存两边字母。最后绝对值最大的一定是假币。

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;


int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        char left[3][6],right[3][6],status[3][6];
        int effect['L'+1];
        bool zero['L'+1];
        memset(zero,0,sizeof(zero));
        memset(effect,0,sizeof(effect));
        for(int i=0;i<3;i++)
            cin>>left[i]>>right[i]>>status[i];//输入
        for(int i=0;i<3;i++)
        {
            switch(status[i][0])
            {
            case 'u':
                {
                      for(int j=0;j<4;j++)
                      {
                        effect[left[i][j]]++;
                        effect[right[i][j]]--;
                      }
                      break;
                }
            case 'd':
                {
                     for(int j=0;j<4;j++)
                     {
                        effect[left[i][j]]--;
                        effect[right[i][j]]++;
                     }
                     break;
                }


            case 'e':
                {
                    for(int j=0;j<4;j++)
                    {
                        zero[left[i][j]]=true;
                        zero[right[i][j]]=true;
                    }
                    break;


                }
            }
        }//影响处理
        int Max=-1; char temp;
        for(int i='A';i<='L';i++)
        {
            if(zero[i]==true) continue;
            if(fabs(effect[i])>Max) {
                temp=i;
                Max=fabs(effect[i]);
            }
        }
        if(effect[temp]<0) printf("%c is the counterfeit coin and it is light.\n",temp);
        else printf("%c is the counterfeit coin and it is heavy.\n",temp);
    }
}

0 0