FXvictory


私信TA

用户名:FXvictory

访问量:3528

签 名:

等  级
排  名 7383
经  验 1266
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校 河南理工大学
专  业

  自我简介:


解题思路:

注意事项:

注意姓名字符串的长度要大于8,因为这个调了很多次


参考代码:

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

struct student
{
	int number;
	char name[9];
	int score;
 } buf[100000];
 
 bool cmp1(student a,student b)
 {
 	return a.number<b.number;
 }
 
 bool cmp2(student a,student b)
 {
 	int tmp=strcmp(a.name,b.name);
 	if(tmp!=0)
 	{
 		return tmp<0;
	 }
	 else
	 {
	 	return a.number<b.number;
	 }
 }
 
bool cmp3(student a,student b)
{
	if(a.score!=b.score)
	{
		return a.score<b.score;
	}
	else
	{
		return a.number<b.number;
	}
}

int main()
{
	int n,c,num=0;
	while(scanf("%d%d",&n,&c)!=EOF)
	{
		num++; 
		if(n>0)
		{ 
		for(int i=0;i<n;i++)
		{
			scanf("%d%s%d",&buf[i].number,buf[i].name,&buf[i].score);
		}
		if(c==1)
		{
			sort(buf,buf+n,cmp1);
		}
		else if(c==2)
		{
			sort(buf,buf+n,cmp2);
		}
		else if(c==3)
		{
			sort(buf,buf+n,cmp3);
		}
		printf("Case %d:\n",num);
		for(int i=0;i<n;i++)
		{
			printf("%06d %s %d\n",buf[i].number,buf[i].name,buf[i].score);
		}
	    }
	    else continue;
	} 
	return 0;
}


 

0.0分

4 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区