ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

1085 PAT单位排行

2022-07-13 14:31:31  阅读:157  来源: 互联网

标签:1085 PAT school second mp2 pair3 排行 const include


注意点

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有