1085 PAT单位排行
2022/7/13 23:23:01
本文主要是介绍1085 PAT单位排行,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
注意点
bool cmp_diy(const pair3& a,const pair3& b){//const xxx & x 作用是引用某个变量,只读它的内容,但不能修改这个引用的变量
代码
#include <iostream> #include <cstdio> #include <string> #include <map> #include <set> #include <utility> #include <vector> #include <algorithm> using namespace std; struct pair3{ string first; float second; int third; }; string chan_name(string a){ string b=a; for(int i=0;a[i]!=NULL;i++){ if(a[i]<='Z'&&a[i]>='A'){ b[i]-=('A'-'a'); } } return b; } bool cmp_diy(const pair3& a,const pair3& b){//const xxx & x 作用是引用某个变量,只读它的内容,但不能修改这个引用的变量 if(a.second!=b.second){ return a.second>b.second; } else{ if(a.third!=b.third){ return a.third<b.third; } else{ return a.first<b.first; } } } int main() { int n; string index; float point; string school; map<string,int> mp; map<string,float> mp2; set<string> st; pair3 pa; vector<pair3> vt; cin>>n; for(int i=0;i<n;i++){ cin>>index>>point>>school; school=chan_name(school); st.insert(school); if(mp.find(school)!=mp.end()){ mp[school]++; } else{ mp[school]=1; } if(mp2.find(school)!=mp2.end()){ ; } else{ mp2[school]=0; } if(index[0]=='B'){ mp2[school]+=point/1.5; } else if(index[0]=='A'){ mp2[school]+=point; } else if(index[0]=='T'){ mp2[school]+=point*1.5; } } for(set<string>::iterator it=st.begin();it!=st.end();it++){ pa.first=*it; pa.second=int(mp2[*it]); pa.third=mp[*it]; vt.push_back(pa); } sort(vt.begin(),vt.end(),cmp_diy); cout<<vt.size()<<endl; int tmpi; int tmpp; for(int i=0;i<vt.size();i++){ if(i==0){ tmpp=vt[i].second; tmpi=i+1; cout<<tmpi; } else{ if(vt[i].second==tmpp){ cout<<tmpi; } else{ tmpi=i+1; tmpp=vt[i].second; cout<<tmpi; } } cout<<" "<<vt[i].first<<" "<<vt[i].second<<" "<<vt[i].third<<endl; } return 0; }
这篇关于1085 PAT单位排行的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-20测试人员都是画画大神,让我看看谁还不会用代码图?
- 2024-05-20年薪百万的程序员都在用的摸鱼方式……
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了