ai_1013.cpp

来自「acm上的1013题,这也是我作业所得, 来源是 East Central N」· C++ 代码 · 共 71 行

CPP
71
字号
#include<iostream.h>
#include<string>
int main()
{
	char Left[7],Right[7],Result[7];
	int TrueCoin[12],FalseCoin[12];
	int i,j,k,n,len;
	for (i=0;i<12;i++)
	{
		TrueCoin[i]=2;
		FalseCoin[i]=0;
	}
	cin>>n;
	for (k=0;k<n;k++)
	{
		for(i=0;i<3;i++)
		{
		    cin>>Left>>Right>>Result;
            len=strlen(Left);
		    switch(Result[0])
			{
		    case 'e':
				{
			        for (j=0;j<len;j++)
					{
	                    TrueCoin[Left[j]-'A']=0;
				        TrueCoin[Right[j]-'A']=0;
					}
					
				}break;
		    case 'u':
				{
				    for (j=0;j<len;j++)
					{
					    FalseCoin[Left[j]-'A']--;
					    FalseCoin[Right[j]-'A']++;
					}
					
				}break;
		    case 'd':
				{
				    for (j=0;j<len;j++)
					{
					    FalseCoin[Left[j]-'A']++;
					    FalseCoin[Right[j]-'A']--;
					}
				}break;
			}
            strset(Left,0);
		    strset(Right,0);
		    strset(Result,0);
		}
		for (j=0;j<12;j++)
		{
			if(TrueCoin[j]==2&&FalseCoin[j]!=0)
			{
				cout<<char(j+'A')<<" is the counterfeit coin and it is ";
				if(FalseCoin[j]<0)
					cout<<"heavy."<<endl;
				else
					cout<<"light."<<endl;
			}
			TrueCoin[j]=2;
			FalseCoin[j]=0;
		}
		
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?