HDUOJ---1862EXCEL排序
EXCEL排序
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12595 Accepted Submission(s): 4955
行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0, 100]内的整数)组成,每个项目间用1个空格隔开。当读到 N=0 时,全部输入结束,相应的结果不要输出。
时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。
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
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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn=;
struct student
{
char no[];
char name[];
int score;
};
student sta[maxn];
int cmp1(const void *a ,const void *b) /*< 学号排序 >*/
{
return strcmp((*(student*)a).no,(*(student*)b).no); /* <升序> */
}
int cmp2(const void *a ,const void *b) /* <升序> */
{ if(strcmp((*(student *)a).name , (*(student *)b).name )==)
return strcmp((*(student *)a).no,(*(student *)b).no); /* <升序> */
else return strcmp((*(student *)a).name , (*(student *)b).name );
} int cmp3(const void *a ,const void *b)
{ if((*(student *)a).score ==(*(student *)b).score) return strcmp((*(student *)a).no,(*(student *)b).no); /* <升序> */
else return (*(student *)a).score -(*(student *)b).score ;
} int main()
{ int n,c,i,cnt=;
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
while(scanf("%d%d",&n,&c),n)
{
memset(sta,,sizeof(sta));
for(i=;i<n;i++)
scanf("%s%s%d",sta[i].no,sta[i].name,&sta[i].score);
switch(c)
{
case : qsort(sta,n,sizeof(sta[]),cmp1); break;
case : qsort(sta,n,sizeof(sta[]),cmp2); break;
case : qsort(sta,n,sizeof(sta[]),cmp3); break;
}
printf("Case %d:\n",cnt++);
for(i=;i<n ;i++)
printf("%s %s %d\n",sta[i].no,sta[i].name,sta[i].score);
}
return ;
}
HDUOJ---1862EXCEL排序的更多相关文章
- 杭电--1862--EXCEL排序--结构体排序
EXCEL排序 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- iOS可视化动态绘制八种排序过程
前面几篇博客都是关于排序的,在之前陆陆续续发布的博客中,我们先后介绍了冒泡排序.选择排序.插入排序.希尔排序.堆排序.归并排序以及快速排序.俗话说的好,做事儿要善始善终,本篇博客就算是对之前那几篇博客 ...
- JavaScript实现常用的排序算法
▓▓▓▓▓▓ 大致介绍 由于最近要考试复习,所以学习js的时间少了 -_-||,考试完还会继续的努力学习,这次用原生的JavaScript实现以前学习的常用的排序算法,有冒泡排序.快速排序.直接插入排 ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- 算法与数据结构(十三) 冒泡排序、插入排序、希尔排序、选择排序(Swift3.0版)
本篇博客中的代码实现依然采用Swift3.0来实现.在前几篇博客连续的介绍了关于查找的相关内容, 大约包括线性数据结构的顺序查找.折半查找.插值查找.Fibonacci查找,还包括数结构的二叉排序树以 ...
- 算法与数据结构(七) AOV网的拓扑排序
今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...
- 使用po模式读取豆瓣读书最受关注的书籍,取出标题、评分、评论、题材 按评分从小到大排序并输出到txt文件中
#coding=utf-8from time import sleepimport unittestfrom selenium import webdriverfrom selenium.webdri ...
- javascript排序
利用array中的sort()排序 w3cfunction sortNumber(a,b) { return a - b } var arr = new Array(6) arr[0] = " ...
随机推荐
- error: 'release' is unavailable: not available in automatic reference counting,该怎么解决
编译出现错误: 'release' is unavailable: not available in automatic reference counting mode.. 解决办法: You nee ...
- scala编程第17章学习笔记(1)——集合类型
列表 列表的初始化及对其首尾的访问: scala> val colors = List("red", "blue", "green") ...
- @Java中使用Jedis操作Redis之一
依赖的jar包:jedis <dependency> <groupId>redis.clients</groupId> <artifactId>jedi ...
- 3Sum Closest leetcode java
题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...
- WebClient.DownloadData突然失灵
有如下的代码: try { byte[] acsMetadata; using (WebClient webClient = new WebClient()) { acsMetadata = we ...
- poj1837--Balance(dp:天平问题)
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10773 Accepted: 6685 Descript ...
- ArcGIS中的批量处理
在实际生产过程中,经常遇到批量处理数据的情况.在ArcGIS中,除自己写代码来处理这类问题外,它提供了一个批量处理的工具,在ToolBox对应的工具上右键即可选择批处理工具. 和单个处理方式一样,输入 ...
- ArcEngine真正释放锁文件,彻底移除图层
ArcMap在加载图层时会自动生成一个lock格式的加锁文件,右击移除图层后,加锁文件也会自动删除.但AE开发中却不能正常删除,移除图层后加锁文件依然存在,这就导致在其他地方无法对该图层进行操作,只有 ...
- AS3的反编译
一个as3写的swf反编译,修改类库: http://www.swfwire.com/ http://www.swfwire.com/decompiler 基于此类库的swf反编译工具(air) ht ...
- The connection to adb is down, and a severe error has occured. 错误
错误:The connection to adb is down, and a severe error has occured. [2010-03-11 09:36:56 - HelloOPone] ...