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

提交了n次,还是WA,思路感觉应该没有错,求大侠帮忙看看,哪里有问题

Posted by huhongqing at 2009-11-05 20:25:14 on Problem 1013
思路就是对从标号A到L的每一个硬币假定其为假币,然后再验证三个条件,如果为真,则此编号的硬币即为假币。
附代码:
#include <stdio.h>
#include <string.h>

typedef struct 
{
	char left[7];
	char right[7];
	char result[5];
}Elemtype;

int main(int argc, char* argv[])
{
	Elemtype data[3];
	char all[12], judge[5], *p, flag, counterreit;
	int i, j, k, num;
	
	//freopen("1.txt", "r", stdin);
	scanf("%d", &num);
	for (i = 0; i < num; i++)
	{
		memset(all, 0, sizeof(char)*12);
		for (j = 0; j < 3; j++)
		{
			scanf("%s%s%s", data[j].left, data[j].right, data[j].result);
			if (strcmp(data[j].result, "even") == 0)
			{
				for (k = 0; k < strlen(data[j].left); k++)
					if (all[data[j].left[k] - 'A'] == 0)
						all[data[j].left[k] - 'A'] = 'y';
				for (k = 0; k < strlen(data[j].right); k++)
					if (all[data[j].right[k] - 'A'] == 0)
						all[data[j].right[k] - 'A'] = 'y';
			}
		}
		flag = 'm';

		for (j = 0; j < 12; j++)
		{
			if (all[j] == 0)
			{
				flag = 'm';
				for (k = 0; k < 3; k++)
				{
					if (strcmp(data[k].result, "even"))
					{
						p = strchr(data[k].left, 'A'+j);
						if (flag == 'm')
						{
							if (p)
							{
								flag = 'l';
								strcpy(judge, data[k].result);
							}
							else
							{
								p = strchr(data[k].right, 'A'+j);
								if (p)
								{
									flag = 'r';
									strcpy(judge, data[k].result);
								}
								else
									break;
							}
						}
						else
						{
							if (p && (flag == 'l' && strcmp(judge, data[k].result) == 0 || flag == 'r' && strcmp(judge, data[k].result) != 0))
							{}
							else if(p)
							{
								break;
							}
							else
							{
								p = strchr(data[k].right, 'A'+j);
								if (p && (flag == 'r' && strcmp(judge, data[k].result) == 0 
									|| flag == 'l' && strcmp(judge, data[k].result) != 0))
								{}
								else
									break;

							}
						}
					}
					
				}
				if (k == 3)
				{
					break;
				}
			}
		}
		counterreit = (char)('A'+j);
		if ((flag == 'l' || flag == 'r') && strcmp(judge, "up") == 0)
			printf("%c is the counterfeit coin and it is light.\n", counterreit);
		else if (flag == 'l' || flag == 'r')
			printf("%c is the counterfeit coin and it is heavy.\n", counterreit);
	}
	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