1 solutions

  • 0
    @ 2025-11-5 15:02:26

    C :

    #include<stdio.h>
    #include<math.h>
    #define false 0
    #define true 1
    void main()
    {
    	int c,cases;
    	scanf("%d",&cases);
    	for(c=1;c<=cases;c++)
    	{
    		char left[3][6],right[3][6],status[3][6];
    		int time['L'+1]={0};  //标记各个字母被怀疑的次数
    		int zero['L'+1]={false};  //标记绝对为真币的字母(令天枰平衡的所有字母)
            int k;
    		for(k=0;k<3;k++)
    			scanf("%s%s%s",left[k],right[k],status[k]);
            int i;
    		for(i=0;i<3;i++)
    		{
    			switch(status[i][0])  //检查天枰状态
    			{
    			    case 'u':     //up,天枰左重右轻
    					{
    					    int j;
    						for(j=0;left[i][j];j++)
    						{
    							time[ left[i][j] ]++;  //左重
    							time[ right[i][j] ]--;  //右轻
    						}
    						break;
    					}
    				case 'd':     //down,天枰左轻右重
    					{
    					    int j;
    						for(j=0;left[i][j];j++)
    						{
    							time[ left[i][j] ]--;  //左轻
    							time[ right[i][j] ]++;  //右重
    						}
    						break;
    					}
    				case 'e':     //down,天枰平衡
    					{
    					    int j;
    						for(j=0;left[i][j];j++)
    						{
    							zero[ left[i][j] ]=true;   //绝对真币
    							zero[ right[i][j] ]=true;   //绝对真币
    						}
    						break;
    					}
    			}
    		}
    
    		int max=-1;  //查找被怀疑程度最高的硬币(假币)
    		char alpha;
    		int j;
    		for(j='A';j<='L';j++)
    		{
    			if(zero[j])  //绝对真币
    				continue;
    
    			if(max<=abs(time[j]))
    			{
    				max=abs(time[j]);
    				alpha=j;
    			}
    		}
    		printf("%c is the counterfeit coin and it is ",alpha);
    		if(time[alpha]>0)
    			printf("heavy.\n");
    		else
                printf("light.\n");
    	}
    }
    
    

    C++ :

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<stdlib.h>
    using namespace std;
    int main(){
    	int  let[13],n,i,j;//,real[13];
    	char a[3][10];
    	scanf("%d", &n);
    	while(n-->0){
    		memset(let, 0, sizeof(let));
    		//memset(real, 0, sizeof(real));
    		for(i=0; i<3; i++) {
    			scanf("%s %s %s",a[0], a[1], a[2]);
    			if(strcmp(a[2],"even")==0){
                    for(j=0; j<(int)strlen(a[0]); j++) let[a[0][j]-'A']=1;
    				for(j=0; j<(int)strlen(a[0]); j++) let[a[1][j]-'A']=1;
    			}
    			else if(strcmp(a[2],"up")==0){
                    for(j=0; j<(int)strlen(a[0]); j++) let[a[0][j]-'A']+=2;
    				for(j=0; j<(int)strlen(a[0]); j++) let[a[1][j]-'A']-=2;
    			}
    			else{
    				for(j=0; j<(int)strlen(a[0]); j++) let[a[0][j]-'A']-=2;
    				for(j=0; j<(int)strlen(a[0]); j++) let[a[1][j]-'A']+=2;
    			}
    		}
    
            //for(i=0; i<12; i++) if(real[i]) let[i]=0;
    		int max=0;
    		for(i=1; i<12; i++) if( let[i]%2==0&& abs(let[i]) > abs(let[max]))  max=i;
    		if(let[max]<0) printf("%c is the counterfeit coin and it is light.\n", 'A'+max);
            else           printf("%c is the counterfeit coin and it is heavy.\n", 'A'+max);
    	}
    	return 0;
    }
    
    
    • 1

    Information

    ID
    16357
    Time
    2000ms
    Memory
    64MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By