解题思路:以map的value排序,如果成绩相同把DaDa放前面去,再找出DaDa在Map当中的位置+1即可。
注意事项:
参考代码:
#include <bits/stdc++.h> using namespace std; typedef pair<string,int>Pair; bool cmp(const Pair &a,const Pair &b){ if(a.second==b.second){ if(b.first.compare("DaDa")==0)return 0; else return 1; } return a.second>b.second; } int main(){ //freopen("f:/123.txt","r",stdin); map<string,int>mp; int n,m; cin>>n; int t=n; string x; while(t--){ cin>>x; mp[x]=0; } cin>>m; while(m--){ for(int i=0;i<n;i++){ string name; int score; cin>>score>>name; mp[name]+=score; } vector<Pair>v(mp.begin(),mp.end()); sort(v.begin(),v.end(),cmp); vector<Pair>::iterator it; for(it=v.begin();it!=v.end();it++){ if(it->first.compare("DaDa")==0){ cout<<it-v.begin()+1<<endl; break; } } } }
0.0分
0 人评分
模拟计算器 (C语言代码)浏览:892 |
C语言训练-立方和不等式 (C语言代码)浏览:751 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:471 |
【数组的距离】 (C语言代码)浏览:742 |
兰顿蚂蚁 (C++代码)浏览:1098 |
分糖果 (C++代码)浏览:1449 |
【亲和数】 (C语言代码)浏览:860 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:619 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:474 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:564 |