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> int main() { int n, i, j, l, e[12], f[12], g[12]; char a[6], b[6], c[4]; scanf("%d", &n); for(i = 0; i < n; i++) { int flag = 0; memset(f, 0, sizeof(f)); memset(g, 0, sizeof(g)); for(j = 0; j < 3; j++) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); scanf("%s %s %s", a, b, c); for(int k = 0; k < 12; k++) { if(flag > 0 && f[k] == 0) continue; memset(e, 0, sizeof(e)); e[k] = -1; int sum = 0; int sum1 = 0; l = 0; while(a[l] != 0) { sum += e[a[l] - 'A']; l++; } l = 0; while(b[l] != 0) { sum1 += e[b[l] - 'A']; l++; } if( c[0] == 'u' && sum > sum1) f[k] = 1; else if(c[0] == 'd' && sum < sum1) f[k] = 1; else if(c[0] == 'e' && sum == sum1) f[k] = 1; else f[k] = 0; } for(int k = 0; k < 12; k++) { if(flag > 0 && g[k] == 0) continue; memset(e, 0, sizeof(e)); e[k] = 1; int sum = 0; int sum1 = 0; l = 0; while(a[l] != 0) { sum += e[a[l] - 'A']; l++; } l = 0; while(b[l] != 0) { sum1 += e[b[l] - 'A']; l++; } if( c[0] == 'u' && sum > sum1) g[k] = 1; else if(c[0] == 'd' && sum < sum1) g[k] = 1; else if(c[0] == 'e' && sum == sum1) g[k] = 1; else g[k] = 0; } flag++; } int ff = 0; int f1; for (int k = 0; k < 12; k++) { if (f[k] == 1) { ff++; f1 = k; } } if(ff == 1) printf("%c is the counterfeit coin and it is light.\n", f1 + 'A'); ff = 0; for ( int k = 0; k < 12; k++) { if (g[k] == 1) { ff++; f1 = k; } } if(ff == 1)printf("%c is the counterfeit coin and it is heavy.\n", f1 + 'A'); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator