"Accepted today?"
10 1 2 3 6 2 02:45:17 2 02:49:01 2 03:17:58 2 03:21:29 4 07:55:48 3 04:25:42 3 06:57:39 2 02:05:02 2 02:16:45 2 02:41:37 0 0 0 0 0
Accepted today? I've got a silver medal :)
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int maxn = 150; struct ss { bool wo; int solve; int h; int m; int s; }; bool cmp(ss a, ss b) { if(a.solve > b.solve) return true; else if(a.solve == b.solve && a.h < b.h) return true; else if(a.solve == b.solve && a.h == b.h && a.m < b.m) return true; else if(a.solve == b.solve && a.h == b.h && a.m == b.m && a.s < b.s) return true; else return false; } int N, G, S, C, M; int main() { while(scanf("%d %d %d %d %d", &N, &G, &S, &C, &M) && (N+G+S+C+M)) { ss f[maxn]; for(int i = 0;i < N; ++i) f[i].wo = false; for(int i = 0;i < N; ++i) { //f[i].wo == false; scanf("%d %d:%d:%d", &f[i].solve, &f[i].h, &f[i].m, &f[i].s); if(i == M-1) f[i].wo = true; } sort(f, f+N, cmp); for(int i = 0;i < N; ++i) { if(f[i].wo != true) continue; if(i < G) cout <<"Accepted today? I've got a golden medal :)\n"; else if(i < G+S) cout <<"Accepted today? I've got a silver medal :)\n"; else if(i < G+S+C) cout<<"Accepted today? I've got a copper medal :)\n"; else cout <<"Accepted today? I've got an honor mentioned :)\n"; break; } } return 0; }
但是为什么下面的代码过不了?求大神解答!!!!
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int maxn = 150; struct ss { bool wo; int solve; int h; int m; int s; }; bool cmp(ss a, ss b) { if(a.solve > b.solve) return true; else if(a.solve == b.solve && a.h < b.h) return true; else if(a.solve == b.solve && a.h == b.h && a.m < b.m) return true; else if(a.solve == b.solve && a.h == b.h && a.m == b.m && a.s < b.s) return true; else return false; } int N, G, S, C, M; int main() { while(scanf("%d %d %d %d %d", &N, &G, &S, &C, &M) && (N+G+S+C+M)) { ss f[maxn]; //for(int i = 0;i < N; ++i) f[i].wo = false; for(int i = 0;i < N; ++i) { f[i].wo == false;//与上面的代码唯一不同的就是我把这个初始化放在了这里面!!!为什么不行?!!不懂 scanf("%d %d:%d:%d", &f[i].solve, &f[i].h, &f[i].m, &f[i].s); if(i == M-1) f[i].wo = true; } sort(f, f+N, cmp); for(int i = 0;i < N; ++i) { if(f[i].wo != true) continue; if(i < G) cout <<"Accepted today? I've got a golden medal :)\n"; else if(i < G+S) cout <<"Accepted today? I've got a silver medal :)\n"; else if(i < G+S+C) cout<<"Accepted today? I've got a copper medal :)\n"; else cout <<"Accepted today? I've got an honor mentioned :)\n"; break; } } return 0; }