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 2011014326 at 2012-10-02 00:30:02 on Problem 1013
这种才是最郁闷的,改都不知道改哪。。。

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

typedef struct
{
	char a[14];
	char b[7];
	char record[5];
}Dollor;

//求绝对值
int positive(int n)
{
	if(n>=0) return n;
	else return n*(-1);
}

int main()
{
	Dollor D[3];
	int dollor[13]={0};
	int i,j,n;
	cin>>n;
	while(n--)
	{
		for(i=0;i<3;i++)
		{
			cin>>D[i].a>>D[i].b>>D[i].record;
			for(j=0;j<strlen(D[i].a);j++)
			{
				if(strcmp(D[i].record,"even")==0)
				{
					dollor[D[i].a[j]-'A']=13;
				    dollor[D[i].b[j]-'A']=13;//不一定是13,任意定,只要最后能和非even中的值区分开就行,因此可大一些
				}
			    if(strcmp(D[i].record,"up")==0)
				{
					dollor[D[i].a[j]-'A']++;
				    dollor[D[i].b[j]-'A']--;
				}
				if(strcmp(D[i].record,"down")==0)
				{
					dollor[D[i].a[j]-'A']--;
				    dollor[D[i].b[j]-'A']++;
				}
			}
		}
		int max=0;
		char x;
		for(i=0;i<12;i++)
		{
			if(dollor[i]<10)
			{
				if(positive(dollor[i])>=positive(max))
				{
					max=dollor[i];
					x='A'+i;
				}
			}
		}

		if(max<0)
		    cout<<x<<" is the counterfeit coin and it is light.\n";
		else
			cout<<x<<" 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