HD-ACM算法专攻系列(17)——find your present (2)
题目描述:
源码:
#include"iostream" #include"string" using namespace std; bool IsFirstHalf(string *strs, int n, string str) { int count = 0; for(int i = 0; i < n; i++) { if(str < strs[i])count++; } return count >= (n / 2 + n % 2); } int main() { int n, count[100], counts[5]; string **strs; strs = new string*[5]; for(int i = 0; i < 5; i++) { strs[i] = new string[100]; } while(cin>>n) { if(n < 0)break; counts[1] = counts[2] = counts[3] = counts[4] = 0; for(int i = 0; i < n; i++) { cin>>count[i]>>strs[0][i]; if(count[i] > 0 && count[i] < 5) { strs[count[i]][counts[count[i]]++] = strs[0][i]; } } for(int i = 0; i < n; i++) { switch(count[i]) { case 5: cout<<100<<endl; break; case 0: cout<<50<<endl; break; default: if(IsFirstHalf(strs[count[i]], counts[count[i]], strs[0][i])) { cout<<55 + 10 * count[i]<<endl; } else { cout<<50 + 10 * count[i]<<endl; } break; } } cout<<endl; } return 0; }