http://acm.hdu.edu.cn/showproblem.php?pid=5038
模拟水题
求出现次数最多的grade。如果有多个grade出现的次数一样多,且还有其他的grade,则把这些出现次数最多的grade按升序输出;否则,输出“Bad Mushroom”。
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <vector> #include <iostream> #include <algorithm> using namespace std; #define RD(x) scanf("%d",&x) #define RD2(x,y) scanf("%d%d",&x,&y) #define clr0(x) memset(x,0,sizeof(x)) int n; int s[1000005]; int cnt[10005]; int main(){ int _,w,cas = 1; RD(_); while(_--){ RD(n); clr0(cnt); for(int i = 0;i < n;++i){ scanf("%d",&w); s[i] = 10000 - (100 - w)*(100 - w); cnt[s[i]]++; } int mn = 20000000,mx = -1; vector <int> ans; for(int i = 0;i <= 10000;++i){ if(cnt[i]){ mn = min(cnt[i],mn); mx = max(cnt[i],mx); } } for(int i = 0;i <= 10000;++i){ if(cnt[i] == mx){ ans.push_back(i); } } printf("Case #%d: ",cas++); if(mn == mx && ans.size() != 1){ puts("Bad Mushroom"); }else{ for(int i = 0;i < ans.size();++i){ printf("%d%c",ans[i]," "[i == ans.size() - 1]); } } } return 0; }