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

code (参考)

Posted by 785045613 at 2011-09-29 20:27:53 on Problem 1013
#include <iostream>
#define sMAX 10
#define wordMAX 12
typedef char STRING[sMAX];
typedef bool SET[wordMAX+1];
using namespace std;
 
SET set1,set2;
 
int del1(STRING s)
{
	int l=strlen(s);
	for(int i=0;i<l;i++)
		set1[int(s[i]-'A')]=true;
	return 0;
}
 
int del2(STRING s)
{
	int l=strlen(s);
	for(int i=0;i<l;i++)
		set2[int(s[i]-'A')]=true;
	return 0;
}
 
bool in(STRING s,int i)
{
	int l=strlen(s);
	for(int j=0;j<l;j++)
		if(i==int(s[j]-'A')) return true;
	return false;
}
 
int add1(STRING s)
{
	for(int i=0;i<12;i++)
		if(!in(s,i)) set1[i]=true;
	return 0;
}
 
int add2(STRING s)
{
	for(int i=0;i<12;i++)
		if(!in(s,i)) set2[i]=true;
	return 0;
}
 
int main()
{
//	freopen("A.in","r",stdin);
	STRING st1,st2,st3;
	int n,j;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		memset(set1,false,sizeof(set1));
		memset(set2,false,sizeof(set2));
		for(j=0;j<3;j++)
		{
			cin>>st1>>st2>>st3;
			if(!strcmp("even",st3))
			{
				del1(st1);
				del1(st2);
				del2(st1);
				del2(st2);
			}
			if(!strcmp("up",st3))
			{
				del1(st1);
				add1(st2);
				del2(st2);
				add2(st1);
			}
			if(!strcmp("down",st3))
			{
				del1(st2);
				add1(st1);
				del2(st1);
				add2(st2);
			}
		}
 
 
		int temp1=-1,temp2=-1;
		for(j=0;j<12;j++)
		{
			if(!set1[j])
			{
				if(temp1==-1) temp1=j;
				else temp1=-1;
			}
			if(!set2[j])
			{
				if(temp2==-1) temp2=j;
				else temp2=-1;
			}
		}
		if(temp1==-1)  cout<<(char)(temp2+'A')<<" is the counterfeit coin and it is heavy."<<endl;
		else		   cout<<(char)(temp1+'A')<<" is the counterfeit coin and it is light."<<endl;
	}
	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