Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能。

Input测试输入包含若干测试用例。每个测试用例的第1行包含两个整数 N (<=100000) 和 C,其中 N 是纪录的条数,C 是指定排序的列号。以下有 N 
行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0, 100]内的整数)组成,每个项目间用1个空格隔开。当读到 N=0 时,全部输入结束,相应的结果不要输出。 
Output对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始)。随后在 N 行中输出按要求排序后的结果,即:当 C=1 时,按学号递增排序;当 C=2时,按姓名的非递减字典序排序;当 C=3 
时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。 
Sample Input

3 1
000007 James 85
000010 Amy 90
000001 Zoe 60
4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98
4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90
0 0

Sample Output

Case 1:
000001 Zoe 60
000007 James 85
000010 Amy 90
Case 2:
000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60
Case 3:
000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90

收获:进一步掌握了结构体的知识,以前感觉看不懂的知识现在能够看懂了,感觉很开心

AC代码

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; struct nood
{
char num[];
char name[];
int score;
} student[]; //学号递增排序
bool cmp1(nood a, nood b)
{
int t_num = strcmp(a.num, b.num);
if(t_num == -)
return true;
else
return false;
} //姓名非递减字典序排序
bool cmp2(nood a, nood b)
{
int t_name = strcmp(a.name, b.name);
if(t_name == )
{
int g = strcmp(a.num, b.num);
if(g == -)
return true;
else
return false;
}
else if(t_name == -)
return true;
else if(t_name == )
return false;
} //成绩非递减排序
bool cmp3(nood a, nood b)
{
if(a.score == b.score)
{
int d = strcmp(a.num, b.num);
if(d == -)
return true;
else
return false;
}
else
return a.score < b.score;
} int main()
{
int n, c;
int flag = ;
while(~scanf("%d %d", &n, &c))
{
flag++;
if(n == && c == )
break;
else
{
for(int i = ; i < n; i++)
{
scanf("%s %s %d", student[i].num, student[i].name, &student[i].score);
}
if(c == )
{
printf("Case %d:\n", flag);
sort(student, student+n, cmp1);
for(int i = ; i < n; i++)
{
printf("%s %s %d\n", student[i].num, student[i].name, student[i].score);
}
}
else if(c == )
{
printf("Case %d:\n", flag);
sort(student, student+n, cmp2);
for(int i = ; i < n; i++)
{
printf("%s %s %d\n", student[i].num, student[i].name, student[i].score);
}
}
else if(c == )
{
printf("Case %d:\n", flag);
sort(student, student+n, cmp3);
for(int i = ; i < n; i++)
{
printf("%s %s %d\n", student[i].num, student[i].name, student[i].score);
}
}
}
} return ;
}

关于字典序排序

比如说有一个随机变量X包含{1 2 3}三个数值。
其字典排序就是{1 2 3} {1 3 2} {2 1 3} {2 3 1} {3 1 2} {3 2 1}

B - EXCEL排序(sort+结构体)的更多相关文章

  1. sort+结构体实现二级排序

    之前介绍的sort函数由于其效率较高,使用较为简单让我用起来那叫一个爽,今天再写一篇使用sort+结构体实现二级排序的方法. 还是先想个问题吧,比如我想输入5个同学的名字和身高,然后得到他们身高的降序 ...

  2. 网上关于sort结构体排序都不完整,我来写一个完整版的 2014-08-09 16:50 60人阅读 评论(0) 收藏

    主要参考sort函数_百度文库, 但是那篇有错误 2.结构体排序,a升,b降,c降 平板视图 打印? 01 #include <iostream> 02 #include <algo ...

  3. 洛谷P1068 分数线划定:sort结构体排序+贪心

    题目描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A市对所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试. 面试分数线根据计划录取人数的150%划定, ...

  4. sort 结构体 正数负数分开排序

    对于结构体排序的一点点记录,之前遇到过结构体排序,个人比较喜欢使用在结构体当中直接重载小于号的方法, 例如说: struct Node{ int index; int del; bool operat ...

  5. PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  6. A - 开门人和关门人(sort+结构体)

    点击打开链接 每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签  到.签离记录,请根据记录找出当天开门和关门的人.  Input 测试输入的第一行给出记录的总天数N ( ...

  7. go语言的排序、结构体排序

    原文:https://studygolang.com/articles/1598 晚上准备动手写点 go 的程序的时候,想起 go 如何排序的问题.排序 sort 是个基本的操作,当然搜索 searc ...

  8. sort+结构体+简单数学+暴力-例题

    A-前m大的数 还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大 ...

  9. 杭电 1862 EXCEL排序(sort+结构体)

    Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能.   Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<=100000 ...

随机推荐

  1. POJ3421(质因数分解)

    X-factor Chains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6501   Accepted: 2023 D ...

  2. (转)ashx 使用Session

    本文转载自:http://www.cnblogs.com/TivonStone/archive/2012/04/06/2434796.html 最近做一个项目,调用ashx文件,其中ashx文件里面有 ...

  3. Mingw版QtCreator调用VS编译的C++库的方法

    https://wenku.baidu.com/view/ae3667fe0b1c59eef8c7b4bc.html

  4. Dubbo入门之一:实例1

    原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicool 1.   概述 Dubbo是一个分布式服务 ...

  5. Python多进程-进程间数据的共享

    不同的进程不能同时修改一份数据,但是不同的进程能对一份数据进行修改 可通过Manager来实现进程间的数据共享 # -*- coding:utf-8 -*- __author__ = "Mu ...

  6. c#抓取网页数据

    写了一个简单的抓取网页数据的小例子,代码如下: //根据Url地址得到网页的html源码 private string GetWebContent(string Url) { string strRe ...

  7. django的render的说明

    return render(request,"homesite.html",locals()) homesite.html页面中的所有内容都可以被渲染,不论是标签还是js代码,包括 ...

  8. touch: cannot touch `/home/tomcat7/logs/catalina.out': Permission denied

    今天打开虚拟机启动tomcat,Y的包这个错,普通用户登录的,一直报这个错误,竟然没有想起来是为什么,真是感到惭愧,其实原因很简单,就是logs文件夹没有读写的权限,一条 chmod -R 777 l ...

  9. 【277】◀▶ Python 列表/元组/字典说明

    目录: 前言 一.访问列表中的值 二.更新列表 三.删除列表元素 四.Python 列表脚本操作符 五.Python 列表函数 & 方法 参考:Python 列表(List)使用说明 列表截取 ...

  10. java字符编码转换研究(转)

    1. 概述 本文主要包括以下几个方面:编码基本知识,java,系统软件,url,工具软件等. 在下面的描述中,将以"中文"两个字为例,经查表可以知道其GB2312编码是" ...