记录编号 336646 评测结果 AAAAAAAAAA
题目名称 韩国明星 最终得分 100
用户昵称 GravatarNemoAre 是否通过 通过
代码语言 C++ 运行时间 0.994 s
提交时间 2016-11-03 15:57:54 内存使用 0.28 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<string>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<map>
  6. using namespace std;
  7. typedef pair<string,int> PAIR;
  8. struct cmp{
  9. bool operator()(const PAIR &P1,const PAIR &P2){
  10. return P1.second<P2.second;
  11. }
  12. };
  13. map<string,int> stars;
  14. int main(){
  15. int n; char name[1000];
  16. FILE *fp,*fp1;
  17. fp = fopen("star.in","r");
  18. fp1 = fopen("star.out","w+");
  19. fscanf(fp,"%d",&n);
  20. fgets(name,1000,fp);
  21. for(int i=0;i<n;i++){
  22. fgets(name,1000,fp);
  23. if(name==""){
  24. i--;
  25. continue;
  26. }
  27. stars.insert(pair<string,int>(name,0));
  28. }
  29. int k,temp;
  30. fscanf(fp,"%d",&k);
  31. fgets(name,1000,fp);
  32. for(int i=0;i<k;i++){
  33. fgets(name,1000,fp);
  34. fscanf(fp,"%d",&temp);
  35. stars[name] += temp;
  36. fgets(name,1000,fp);
  37. }
  38. vector<PAIR> t(stars.begin(),stars.end());
  39. sort(t.begin(),t.end(),cmp());
  40. for(int i=n-1;i>=0;i--){
  41. const char *s = t[i].first.c_str();
  42. fprintf(fp1,"%s%d\n",s,t[i].second);
  43. }
  44. return 0;
  45. }