Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

很高兴啊!谢谢大牛的测试数据!

Posted by chenxuan123456789 at 2012-08-03 10:27:29 on Problem 1013
#include <stdio.h>
#include <string.h>
char str1[3][10];
char str2[3][10];
char result[3][10];
char len[30];
char s;
int weight[13],flag,flagl;
void judgew()
{
	int i,j,f1,sum1,sum2,f2,len1,len2;
	 for(j=0;j<3;j++)
	 {
		f1=1;
		f2=1;
		sum1=0;
		sum2=0;
		len1=strlen(str1[j]);
		len2=strlen(str2[j]);
		for(i=0;i<len1;i++)
		sum1+=weight[str1[j][i]-'A'+1];
		for(i=0;i<len2;i++)
		sum2+=weight[str2[j][i]-'A'+1];
	//	printf("%d %d\n",sum1,sum2);
			switch(result[j][0])
			{
			case'u':
				if(sum1>=sum2)
					f2=0;
				break;
			case'e':
				if(sum1>sum2||sum1<sum2)
					f2=0;
				break;
			case'd':
				if(sum2>=sum1)
					f2=0;
				break;
			}
			if(!f2)
			{
				f1=0;
				break;
			}
	  if(!f1)
	  break;
	 }
	 if(f1&&f2)
	  flag=1;
}
void judgel()
{ 
	int i,j,f1,sum1,sum2,f2,len1,len2;
	 for(j=0;j<3;j++)
	 {
		f1=1;
		f2=1;
		sum1=0;
		sum2=0;
		len1=strlen(str1[j]);
		len2=strlen(str2[j]);
		for(i=0;i<len1;i++)
	    sum1+=weight[str1[j][i]-'A'+1];
        for(i=0;i<len2;i++)
		sum2+=weight[str2[j][i]-'A'+1];
			switch(result[j][0])
			{
			case'u':
				if(sum1>=sum2)
					f2=0;
				break;
			case'e':
				if(sum1>sum2||sum1<sum2)
					f2=0;
				break;
			case'd':
				if(sum2>=sum1)
					f2=0;
				break;
			}
			if(!f2)
			{
				f1=0;
				break;
			}
		if(!f1)
			break;
	 }
	 if(f1&&f2)
	  flagl=1;
}
int main()
{
	int cases,k;
	scanf("%d",&cases);
	getchar();
	while(cases--)
	{
		memset(weight,0,sizeof(weight));
		for(k=0;k<3;k++)
		{
			gets(len);
			sscanf(len,"%s%s%s",&str1[k],&str2[k],&result[k]);
		}
		//getchar();
		for(k=1;k<=12;k++)
		{
			weight[k]=1;
			flag=0;
			judgew();
			weight[k]=0;
			if(flag)
			break;
		}
		if(flag)
		printf("%c is the counterfeit coin and it is light.\n",k+'A'-1);
		else
		{
			memset(weight,0,sizeof(weight));
			for(k=1;k<=12;k++)
			{
				weight[k]=-1;
				s='A'+k-1;
				flagl=0;
				judgel();
				weight[k]=0;
				if(flagl)
				break;
			}
			printf("%c is the counterfeit coin and it is heavy.\n",k+'A'-1);
		}
	}
	return 1;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator