Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用的排除法,假设其中一个为假,带入验证#include <stdio.h> #include <string.h> typedef struct Node { int s1[12]; int s2[12]; int flag; }Node; void solve() { int i, j, k, w, num; int arry[20]; char str1[13], str2[13], temp[13]; char str[2][10] = {"light","heavy"}; Node dest[3]; arry[12] = 1; scanf("%d",&num); getchar(); for (i = 0; i < num; i++) { memset(arry,0,sizeof(arry)); memset(dest,0,sizeof(dest)); for (j = 0; j < 3; j++) { scanf("%s %s %s",str1,str2,temp); for (k = 0; str1[k] != '\0'; k++) { dest[j].s1[str1[k]-'A'] = 1; dest[j].s2[str2[k]-'A'] = 1; arry[str1[k]-'A'] = 1; arry[str2[k]-'A'] = 1; } if (strcmp(temp,"even") == 0) dest[j].flag = 1; else if (strcmp(temp,"up") == 0) dest[j].flag = 2; else dest[j].flag = 3; } w = 0; while (w < 2) { for (j = -1; j < 11; ) { while (arry[++j] == 0); if (j >= 12) break; for (k = 0; k < 3; k++) { if (dest[k].s1[j] == 0 && dest[k].s2[j] == 0 && dest[k].flag != 1) break; if (dest[k].s1[j] == 1 && dest[k].flag != 3 - w) break; if (dest[k].s2[j] == 1 && dest[k].flag != 2 + w) break; } if (k >= 3) { printf("%c is the counterfeit coin and it is %s. \n",j+'A',str[w]); w++; break; } } w++; } } } int main(void) { solve(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator