其他分享
首页 > 其他分享> > 1085 PAT单位排行

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,school,second,mp2,pair3,排行,const,include
来源: https://www.cnblogs.com/wodeblog1982/p/16473730.html