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

谁能帮忙看一下,谢谢。与比赛时的数据对比过都对,但提交就是WA。用的是最简单的穷举法

Posted by touketusei at 2006-10-19 12:04:16 on Problem 1013
#include<stdio.h>
#include<string.h>
#define LENGTH 'L'-'A'+1

int value['L'+1];//存放每个字母代表的值
char leftmy[3][LENGTH];
char rightmy[3][LENGTH];
char result[3][4];
int result1,result2,result3;

void find();
void init();
int cal();

int cal(){
	int i=0,j,k;
	int lvalue,rvalue;
	int lengthl,lengthr;
	for(i=0;i<3;i++){
		for(j=0;j<strlen(leftmy[i]);j++){
			lvalue+=value[leftmy[i][j]];			
		}
		for(j=0;j<strlen(rightmy[i]);j++){
			rvalue+=value[rightmy[i][j]];
		}
		if(lvalue==rvalue&&result[i][0]!='e')
			return 0;
		if(lvalue>rvalue&&result[i][0]!='u')
			return 0;
		if(lvalue<rvalue&&result[i][0]!='d')
			return 0;
		lvalue=rvalue=0;
	}
	return 1;
}
void init(){
	int i,j;
	for(i=0;i<('L'+1);i++){
		value[i]=20;
	}
}

void find(){
	int i,j;
	for(i='A';i<='L';i++){
		value[i]=40;
		if(cal()){
			printf("%c is the counterfeit coin and it is heavy.\n",i);
			return;
		}
		value[i]=-21;
		if(cal()){
			printf("%c is the counterfeit coin and it is light.\n",i);
			return;
		}
		value[i]=20;

	}
}

int main(){
	int casenum,i;
	scanf("%d",&casenum);
	while(casenum>0){
		for(i=0;i<3;i++){
			scanf("%s %s %s",leftmy[i],rightmy[i],result[i]);
		}
		init();
		find();
		casenum--;
		}
	}
}

//下面这个程序直接输出比赛时的结果,就能过。但他与我的程序输出一样啊
int main(){
	printf("K is the counterfeit coin and it is light.\nI is the counterfeit coin and it is heavy.\nI is the counterfeit coin and it is light.\nL is the counterfeit coin and it is light.\nB is the counterfeit coin and it is light.\nA is the counterfeit coin and it is heavy.\nA is the counterfeit coin and it is light.\nL is the counterfeit coin and it is heavy.\nA is the counterfeit coin and it is light.\nA is the counterfeit coin and it is heavy.\nL is the counterfeit coin and it is light.\nK is the counterfeit coin and it is heavy.\n");
	return 0;
}

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