PTA写BUG日志——STL库函数(算法笔记上机实战)

Vector

第一例

PTA甲级1039

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.

Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤40,000), the number of students who look for their course lists, and K (≤2,500), the total number of courses. Then the student name lists are given for the courses (numbered from 1 to K) in the following format: for each course i, first the course index i and the number of registered students N
i

(≤200) are given in a line. Then in the next line, N
i

student names are given. A student name consists of 3 capital English letters plus a one-digit number. Finally the last line contains the N names of students who come for a query. All the names and numbers in a line are separated by a space.

Output Specification:
For each test case, print your results in N lines. Each line corresponds to one student, in the following format: first print the student’s name, then the total number of registered courses of that student, and finally the indices of the courses in increasing order. The query results must be printed in the same order as input. All the data in a line must be separated by a space, with no extra space at the end of the line.

Sample Input:
11 5
4 7
BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
1 4
ANN0 BOB5 JAY9 LOR6
2 7
ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
3 1
BOB5
5 9
AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9
结尾无空行
Sample Output:
ZOE1 2 4 5
ANN0 3 1 2 5
BOB5 5 1 2 3 4 5
JOE4 1 2
JAY9 4 1 2 4 5
FRA8 3 2 4 5
DON2 2 4 5
AMY7 1 5
KAT3 3 2 4 5
LOR6 4 1 2 4 5
NON9 0
结尾无空行
第一次提交说最后一个测试点超时
后来同一份代码又提交了一次,AC了
应该是系统问题~
看到有博客说用哈希来着,咱懒咱就不整活儿了

这题涉及到的vector知识点主要有:

  • 排序:sort(student[name].begin(),student[name].end())
  • 计算vector容器大小:student[name].size()
  • 在vector后面插入新的元素:student[name].push_back(id);

俺代码当中还用了map,不懂的小伙伴可以先跳过,就当student[name]是vector变量名vec好啦~

//1039
#include<bits/stdc++.h>
using namespace std;
int n,k;//n->student,k->course
//每行输入编码,学生
map<string,vector<int> >student; 
int main(){
	scanf("%d%d",&n,&k);
	while(k--){
		int id,num;
		scanf("%d%d",&id,&num);
		string name;
		while(num--){
			cin>>name;
			student[name].push_back(id);
		}	
	}
	while(n--){
		string name;
		cin>>name;
		cout<<name;
		printf(" %d",student[name].size());
		sort(student[name].begin(),student[name].end());
		for(int i=0;i<student[name].size();i++){
			printf(" %d",student[name][i]);
		}
		if(n)
		printf("\n");
	}
	return 0;
} 

第二例

PTA甲级1047

Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.

Input Specification:
Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤40,000), the total number of students, and K (≤2,500), the total number of courses. Then N lines follow, each contains a student’s name (3 capital English letters plus a one-digit number), a positive number C (≤20) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.

Output Specification:
For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students’ names in alphabetical order. Each name occupies a line.

Sample Input:
10 5
ZOE1 2 4 5
ANN0 3 5 2 1
BOB5 5 3 4 2 1 5
JOE4 1 2
JAY9 4 1 2 5 4
FRA8 3 4 2 5
DON2 2 4 5
AMY7 1 5
KAT3 3 5 4 2
LOR6 4 2 4 1 5
结尾无空行
Sample Output:
1 4
ANN0
BOB5
JAY9
LOR6
2 7
ANN0
BOB5
FRA8
JAY9
JOE4
KAT3
LOR6
3 1
BOB5
4 7
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
5 9
AMY7
ANN0
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1

结尾无空行
和第一题很像,就是输入输出的顺序刚好相反。
用了下面这一段代码,结果最后一个测试点的时候因为cin和cout超时了
参考用了cin,cout加速的代码:

ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);	

结果内存超限了,/(ㄒoㄒ)/~~

//1047
#include<bits/stdc++.h>
using namespace std;
int n,k;
map<int,vector<string> >course;
bool cmp(string a,string b){
	return a<b;
}
int main(){
	
	while(n--){
		string name;
		cin>>name;
		int id;
		int num;
		cin>>num;
		while(num--){
			cin>>id;
			course[id].push_back(name);	
		}
	}
	for(int id=1;id<=k;id++){
		printf("%d %d\n",id,course[id].size());
		sort(course[id].begin(),course[id].end(),cmp);
		for(int i=0;i<course[id].size();i++){
			cout<<course[id][i];
			if(!(id==k&&i==course[id].size()-1)){
				cout<<endl;
			}
		}
	}
	
	return 0;
}

解决超时问题的代码将cin,cout全部改成scanf
这里主要涉及到的知识点是string类型自带的**c_str()**函数,可以将string类型转化为const char 类型的数组通过printf()输出
AC代码如下:

//1047
#include<bits/stdc++.h>
using namespace std;
int n,k;
map<int,vector<string> >course;
bool cmp(string a,string b){
	return a<b;
}
int main(){
	scanf("%d %d",&n,&k);
	while(n--){
		string name;
		cin>>name;
		int id;
		int num;
		cin>>num;
		while(num--){
			//cin>>id;
			scanf("%d",&id);
			course[id].push_back(name);	
		}
	}
	for(int id=1;id<=k;id++){
		printf("%d %d\n",id,course[id].size());
		sort(course[id].begin(),course[id].end(),cmp);
		for(int i=0;i<course[id].size();i++){
			//cout<<course[id][i];
			printf("%s",course[id][i].c_str());
			if(!(id==k&&i==course[id].size()-1)){
				//cout<<endl;
				printf("\n");
			}
		}
	}
	
	return 0;

Set

PTA甲级1063
这里补充一下《算法笔记》上没有提过的set内置函数:set求并集、交集与差集

Given two sets of integers, the similarity of the sets is defined to be N
c

/N
t

×100%, where N
c

is the number of distinct common numbers shared by the two sets, and N
t

is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

Input Specification:
Each input file contains one test case. Each case first gives a positive integer N (≤50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (≤10
4
) and followed by M integers in the range [0,10
9
]. After the input of sets, a positive integer K (≤2000) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

Output Specification:
For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

Sample Input:
3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
2
1 2
1 3
结尾无空行
Sample Output:
50.0%
33.3%
结尾无空行

主要涉及的有:

  • set_intersection(取集合交集)
  • set_union(取集合并集)
  • set_difference(取集合差集)、
  • set_symmetric_difference(取集合对称差集)等函数。

这是第一版,思路是每次输入两个序列编号,分别进行求交集与并集,但是这种思路会有一个样例运行超时😟

#include<bits/stdc++.h>
using namespace std;
int n,m,temp;
int k;
int main(){
	scanf("%d",&n);
	vector<set<int> >num(n+1);
	for(int i=1;i<=n;i++){
		scanf("%d",&m);
		while(m--){
			scanf("%d",&temp);
			num[i].insert(temp);
		}
	}
	scanf("%d",&k);
	while(k--){
		int nc=0,nt=0;//nc是两个共有的不同的数量,nt是总共的不同数字的数量
		int a,b;
		scanf("%d %d",&a,&b);
		set<int>total;//并集
		set<int>same;//交集
		set_union(num[a].begin(),num[a].end(),num[b].begin(),num[b].end(),inserter(total,total.begin()));
		set_intersection(num[a].begin(),num[a].end(),num[b].begin(),num[b].end(),inserter(same,same.begin()));
		printf("%.1f%%",100.0*same.size()/total.size());
		if(k){
			printf("\n");
		}
		total.clear();
	}
	return 0;
} 

这是第二版AC版本,主要利用了set自动排序的功能迭代那块查了半天的bug也是没谁了
总之还是学了不少知识点哒😊

#include<bits/stdc++.h>
using namespace std;
int n,m,temp;
int k;
int main(){
	scanf("%d",&n);
	vector<set<int> >num(n+1);
	for(int i=1;i<=n;i++){
		scanf("%d",&m);
		while(m--){
			scanf("%d",&temp);
			num[i].insert(temp);
		}
	}
	scanf("%d",&k);
	while(k--){
		int nc=0,nt=0;//nc是两个共有的不同的数量,nt是总共的不同数字的数量
		int a,b;
		scanf("%d %d",&a,&b);
		//利用的是排好顺序的特性
		set<int>::iterator it1,it2;
		it1=num[a].begin();
		it2=num[b].begin();
		nt=num[a].size();
		for(;it1!=num[a].end();){
			if(it2==num[b].end())break;
			if(*it1==*it2){
			
				nc++;
				it1++;
				it2++;
			}else if(*it2<*it1){
				it2++;
				nt++;
			}else if(*it2>*it1){
				it1++;
			}
		}
		for(;it2!=num[b].end();it2++)nt++;
		//printf("%d %d\n",nc,nt);
		printf("%.1f%%",100.0*nc/nt);
		if(k){
			printf("\n");
		}

	}
	return 0;
} 

String

PTA甲级1060
第一版,过了3/7,因为没有考虑小数点位置的问题以及输入本身n>length()的问题,所以……

//1060
#include<bits/stdc++.h>
using namespace std;
int n;
string a,b;
string change(string num,int n){
	string ans="0.";
	int d;
	if(num.find(".")!=string::npos){
		d=num.find(".");	
	}else d=num.length();
	for(int i=0;i<n;i++){
		ans+=num[i];
	}
	ans+="*10^";
	ans+=to_string(d);
	return ans;
}
int main(){
	scanf("%d",&n);
	cin>>a>>b;
	a=change(a,n);
	b=change(b,n);
	if(a==b){
		printf("YES %s",a.c_str());
	}else{
		printf("NO %s %s",a.c_str(),b.c_str());
	}
	return 0;
}

第二版 考虑了小数点的问题以及后置零的问题,但是仍然有一个样例没有通过~

//1060
#include<bits/stdc++.h>
using namespace std;
int n;
string a,b;
//首先判断是否相同
string change(string a,int n){
	int len=a.length();
	string ans="0.";
	int i=0;
	//删除前导0
	while(a[i]=='0'){
		i++;  
	}
	a.erase(0,i);
	//printf("删除前导零:%s\n",a.c_str());
	//删除后置零
	len=a.length();
	int d=len;
	if(a.find(".")!=string::npos){
		i=len-1;
		while(a[i]=='0'){
			i--;
		}
		if(i!=len-1)
			a.erase(i+1,len-i-1);
		d=a.find(".");
		a.erase(a.begin()+d);//删除小数点 
	}	
	//printf("删除后置零:%s\n",a.c_str());
	//整理出所有的数字
	len=a.length();
	if(len>n){
		a=a.substr(0,n);
		//printf("长度过大,缩减之后:%s\n",a.c_str());
	}else{
		while(len<n){
			a+="0";
			len++;
		}
	}
	ans+=a;
	ans+="*10^";
	ans+=to_string(d);
	//printf("最终:%s\n",ans.c_str());
	return ans;
}
int main(){
	scanf("%d",&n);
	cin>>a>>b;
	a=change(a,n);
	b=change(b,n);
	if(a==b){
		printf("YES %s",a.c_str());
	}else{
		printf("NO %s %s",a.c_str(),b.c_str());
	}
	return 0;
}

后来刷题解博客发现第二版没有解决小数的问题,就是下面这种情况没有考虑:

2 0.0015 0000.001520000
YES 0.15*10^-2

于是添加了一个判断d是否为0的if结构即可AC
AC代码如下自认为注释还是蛮棒的,就是写的不是很整洁:👶

//1060
#include<bits/stdc++.h>
using namespace std;
int n;
string a,b;
//首先判断是否相同
string change(string a,int n){
	int len=a.length();
	string ans="0.";
	int i=0;
	//删除前导0
	while(a[i]=='0'){
		i++;  
	}
	a.erase(0,i);
	//printf("删除前导零:%s\n",a.c_str());
	//删除后置零
	len=a.length();
	int d=len;
	if(a.find(".")!=string::npos){
		i=len-1;
		while(a[i]=='0'){
			i--;
		}
		if(i!=len-1)
			a.erase(i+1,len-i-1);
		d=a.find(".");
		a.erase(a.begin()+d);//删除小数点 
	}
	len=a.length();
	//需要特判的一种情况是 d=0
	if(d==0){
		i=0;
		while(a[i]=='0'){
			i++;
		}
		
		a.erase(0,i);
		d=-i;
	}	
	//printf("删除后置零:%s\n",a.c_str());
	//整理出所有的数字
	if(len>n){
		a=a.substr(0,n);
		//printf("长度过大,缩减之后:%s\n",a.c_str());
	}else{
		while(len<n){
			a+="0";
			len++;
		}
	}
	ans+=a;
	ans+="*10^";
	ans+=to_string(d);
	//printf("最终:%s\n",ans.c_str());
	return ans;
}
int main(){
	scanf("%d",&n);
	cin>>a>>b;
	a=change(a,n);
	b=change(b,n);
	if(a==b){
		printf("YES %s",a.c_str());
	}else{
		printf("NO %s %s",a.c_str(),b.c_str());
	}
	return 0;
}

Map

第一弹:打表

PTA乙级1044
其实这题难度不大,涉及到的map知识点也不是很多。唯一的注意点是,26,39这类13可以整除的数字转化成火星文后,低位是没有0的~

//1044火星数字
#include<bits/stdc++.h>
using namespace std;
string num[13]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string up[12]={"tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
map<string,string>mp;
//首先是预处理:感觉像是打表
void fun(){ 
	for(int i=0;i<13;i++){
		//数字转化为火星文 
		mp[to_string(i)]=num[i];
		//火星文转化成数字 
		mp[num[i]]=to_string(i);
	}
	int h,l;
	mp["13"]="tam";
	mp["tam"]="13";
	for(int i=14;i<169;i++){
		h=i/13;
		l=i%13;
		if(l){
			//数字转化成火星文 
			mp[to_string(i)]=up[h-1]+" "+num[l];
			//火星文转化成数字
			mp[up[h-1]+" "+num[l]] =to_string(i);
		}else{
			//数字转化成火星文 
			mp[to_string(i)]=up[h-1];
			//火星文转化成数字
			mp[up[h-1]] =to_string(i);
		}
	}
} 
string str;
int main(){
	int n;
	scanf("%d",&n);
	getchar();
	fun();
	while(n--){
		getline(cin,str);
		printf("%s",mp[str].c_str());
		if(n)printf("\n");
	}
	
	return 0;
} 

第二弹:水题以及自信💜up

PTA1054甲级
难点可能是24bits,所以一开始就不能用普通的数组去存储结果叭,但我写题目是按着《算法笔记》的顺序来的,所以一开始就知道是用map,怎么说呢,有一种被提前透题的赶脚~

//1054
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int n,m;
string str;
string more="";
int maxn=0;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			cin>>str;
			if(!mp[str]){
				mp[str]=1;
			}else{
				mp[str]++;
			}
			if(maxn<mp[str]){
				maxn=mp[str];
				more=str;
			}
		}
	}
	printf("%s",more.c_str());
	return 0;
}

第三弹

PTA甲级1071

更像是考字符串专题,用了大写转小写transform方法,以及获取子串的substr方法

AC代码见下:

#include<bits/stdc++.h>
using namespace std;
string str;
int maxn=0;
string more="";
string temp;
map<string,int> mp;
int main(){
	getline(cin,str);
	int r;
	//全部改成小写
	transform(str.begin(),str.end(),str.begin(),::tolower) ;
	for(int l=0;l<str.length();){
		while(!(str[l]<='9'&&str[l]>='0'||str[l]>='a'&&str[l]<='z')&&l<str.length())l++;
		if(l>=str.length())break;
		r=l;
		while((str[r]<='9'&&str[r]>='0'||str[r]>='a'&&str[r]<='z')&&r<str.length()){
			r++;
		}
		temp=str.substr(l,r-l);
		if(mp[temp])mp[temp]++;
		else mp[temp]=1;
		if(mp[temp]>maxn){
			maxn=mp[temp];
			more=temp;
		}
		l=r+1;
	}
	printf("%s %d",more.c_str(),maxn);
	return 0;
} 

第四弹

PTA甲级1022
这题很贼,涉及到 multimap

  1. multimap创建数组:这个比较基础,主要涉及的与map的区别是make_pair(a,b)
  2. multimap相同键值的排序
  3. multimap遍历输出:有三种方式,下面是我选的方式

for(int k=0;k!=year.count(op);k++,it++){
//printf("%s\n",(it->second).c_str());
ans.insert(make_pair(it->second,it->first));
}

AC的代码比较长,其实很多操作是重复的,要是用函数封装,string数组加成会让代码简洁一半,不过俺懒啦,就这样叭,之后有时间STL这块一定会重刷一遍,尽量提供简洁的题解~😊

//1022
#include<bits/stdc++.h>
using namespace std;
int n,m; 
multimap<string,string>title;
multimap<string,string>author;
multimap<string,string>word;
multimap<string,string>publisher;
multimap<string,string>year;
string id,temp;
void doWord(string text){
	int l=0,r=0;
	while(l<text.length()){
		r++;
		if(text[r]==' '||r==text.length()){
			word.insert(make_pair(text.substr(l,r-l),id));
			//cout<<"debug:"<<text.substr(l,r-l) <<endl;
			l=r+1;
			r=l;
		}
	}
	return;
} 
int main(){
	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++){
		getline(cin,id);
		for(int j=1;j<6;j++){
			getline(cin,temp);
			pair<string,string> p(temp,id);
			switch(j){
				case 1:title.insert(p);
					break;
				case 2:author.insert(p);
					break;
				case 3:doWord(temp);//关键词查询比较麻烦
				//关键词查询需要一个个剖开 
					break;
				case 4:publisher.insert(p);
					break;
				default:year.insert(p);
					break;
			}	
		}
	}
	//检查输出
	//cout<<id<<" "<<temp<<"!"<<endl; 
	scanf("%d",&m);
	getchar();
	string op;
	multimap<string,string>::iterator it;
	multimap<string,string>ans;
	while(m--){
		getline(cin,op);
		printf("%s\n",op.c_str());
		//cout<<op<<"+\n";
		if(op[0]=='1'){
			op=op.substr(3,op.length()-3);	
			//输出键值相同的所有元素
			it=title.find(op); 
			if(!title.count(op)){
				printf("Not Found");
				if(m)printf("\n");
				continue;
			}
			for(int k=0;k!=title.count(op);k++,it++){
				//printf("%s\n",(it->second).c_str());
				ans.insert(make_pair(it->second,it->first));
			}
			it=ans.begin();
			int y=title.count(op);
			for(;it!=ans.end();it++,y--){
				printf("%s",(it->first).c_str());
				if(m||y)printf("\n");
			}
			ans.clear();
		}else if(op[0]=='2'){
			op=op.substr(3,op.length()-3);	
			//输出键值相同的所有元素
			it=author.find(op);
			if(!author.count(op)){
				printf("Not Found");
				if(m)printf("\n");
				continue;
			}
			for(int k=0;k!=author.count(op);k++,it++){
				//printf("%s\n",(it->second).c_str());
				ans.insert(make_pair(it->second,it->first));
			}
			int y=author.count(op);
			it=ans.begin();
			for(;it!=ans.end();it++,y--){
				printf("%s",(it->first).c_str());
				if(m||y)printf("\n");
			}
			ans.clear();
		}else if(op[0]=='3'){
			op=op.substr(3,op.length()-3);	
			//输出键值相同的所有元素
			it=word.find(op);
			if(!word.count(op)){
				printf("Not Found");
				if(m)printf("\n");
				continue;
			}
			for(int k=0;k!=word.count(op);k++,it++){
				//printf("%s\n",(it->second).c_str());
				ans.insert(make_pair(it->second,it->first));
			}
			int y=word.count(op);
			it=ans.begin();
			for(;it!=ans.end();it++,y--){
				printf("%s",(it->first).c_str());
				if(m||y)printf("\n");
			}
			ans.clear();
		}else if(op[0]=='4'){
			op=op.substr(3,op.length()-3);	
			//输出键值相同的所有元素
			it=publisher.find(op);
			if(!publisher.count(op)){
				printf("Not Found");
				if(m)printf("\n");
				continue;
			}
			for(int k=0;k!=publisher.count(op);k++,it++){
				//printf("%s\n",(it->second).c_str());
				ans.insert(make_pair(it->second,it->first));
			}
			it=ans.begin();
			int y=publisher.count(op);
			for(;it!=ans.end();it++,y--){
				printf("%s",(it->first).c_str());
				if(m||y)printf("\n");
			}
			ans.clear();
		}else{
			op=op.substr(3,op.length()-3);	
			//输出键值相同的所有元素
			it=year.find(op);
			if(!year.count(op)){
				printf("Not Found");
				if(m)printf("\n");
				continue;
			}
			for(int k=0;k!=year.count(op);k++,it++){
				//printf("%s\n",(it->second).c_str());
				ans.insert(make_pair(it->second,it->first));
			}
			int y=year.count(op);
			it=ans.begin();
			for(;it!=ans.end();it++,y--){
				printf("%s",(it->first).c_str());
				if(m||y)printf("\n");
			}
			ans.clear();
		}
	}
	
	return 0;
} 

PTA甲级1012

排序题,难点在于排序实际上是1,1,3,4,5而不是1,1,2,3,4

#include<bits/stdc++.h>
using namespace std;
//有一个测试点没有通过 
struct Ans{
	int rank;
	char kind;//1--c,2--m,3--e,4--a;
};
struct Stu{
	int id;
	int c,m,e,a;
};
int n,k;
vector<int>cc,mm,ee,aa;
map<int,Ans>info;
bool cmp(int a,int b){
	return a>b;
}
int Find(vector<int>st,int value){
	int len=st.size();
	int index=1;
	for(int i=0;i<len;i++){
		if(i!=0){
			if(st[i]!=st[i-1]){
				index=i+1;
			}
		}
		if(value==st[i]){
			return index;
		}
	}
}
//查看排名并列的情况
/*
1、1、3、4、5,而不是1、1、2、3、4
*/ 
int main(){
	scanf("%d %d",&n,&k);
	vector<Stu>stu(n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&stu[i].id,&stu[i].c,&stu[i].m,&stu[i].e);
		stu[i].a=(stu[i].c+stu[i].m+stu[i].e)/3;
		cc.push_back(stu[i].c);
		mm.push_back(stu[i].m);
		ee.push_back(stu[i].e);
		aa.push_back(stu[i].a);
	}
	sort(cc.begin(),cc.end(),cmp);
	sort(mm.begin(),mm.end(),cmp);
	sort(ee.begin(),ee.end(),cmp);
	sort(aa.begin(),aa.end(),cmp);
	
	//计算每一个id对应的最好的排名 
	for(int i=0;i<n;i++){
		int c=stu[i].c;
		int m=stu[i].m;
		int e=stu[i].e;
		int a=stu[i].a;
		int ranka=Find(aa,a);
		int ranke=Find(ee,e);
		int rankm=Find(mm,m);
		int rankc=Find(cc,c);
		if(ranka<=rankc&&ranka<=rankm&&ranka<=ranke){
			info[stu[i].id].kind='A';
			info[stu[i].id].rank=ranka;
		}else if(rankc<=rankm&&rankc<=ranke){
			info[stu[i].id].kind='C';
			info[stu[i].id].rank=rankc;
		}else if(rankm<=ranke){
			info[stu[i].id].kind='M';
			info[stu[i].id].rank=rankm;
		}else{
			info[stu[i].id].kind='E';
			info[stu[i].id].rank=ranke;
		}
	} 
	//查询排名
	int temp;
	map<int,Ans>::iterator it;
	for(int i=0;i<k;i++){
		scanf("%d",&temp);
		it=info.find(temp);
		if(it!=info.end()){
			printf("%d %c",info[temp].rank,info[temp].kind);
			
		}else{
			printf("N/A");
		}
		if(i!=k-1)printf("\n");
	} 
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值