文章

211

粉丝

1

获赞

1164

访问

48.7k

头像
EXCEL排序 题解:
P1338 浙江大学机试题
发布于2026年3月15日 19:41
阅读数 91

#include<bits/stdc++.h>
using namespace std;
struct node{
	string tag,name;
	int score;
};	
bool cmp1(node a,node b){
	return a.tag < b.tag;	
}	
bool cmp2(node a,node b){
	if(a.name == b.name)
		return a.tag < b.tag;	
	else 
		return a.name < b.name;	
}	
bool cmp3(node a,node b){
	if(a.score == b.score)
		return a.tag < b.tag;	
	else 
		return a.score < b.score;		
}
int main(){
	int n,c;
	while(cin >> n >> c){
		if(n==0)
			break;
		vector<node> stu(n);
		for(int i=0;i<n;i++)
			cin >> stu[i].tag >> stu[i].name >> stu[i].score;
		cout << "Case:" << endl;
		if(c == 1)
			sort(stu.begin(),stu.end(),cmp1);
		else if(c == 2)
			sort(stu.begin(),stu.end(),cmp2);
		else if(c == 3)
			sort(stu.begin(),stu.end(),cmp3);
		for(auto it:stu)
			cout << it.tag << " " << it.name << " " << it.score << endl;
	}	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发