hdu1862
//开始把student stu[100000]放置在main()中导致栈溢出,所以必须放在全局位置,
//可以调用数组的排序函数sort,包含头文件#include<algorithm>,在默认的情况下,数组sort函数进行升序排序
//控制sort的第三个参数,传递函数指针进去,可以按照自己写的函数进行排序
#include<iostream>
#include<algorithm>
using namespace std;
class student{
public:
char number[7];
char name[9];
short mark;
};
student stu[100000];
bool cmp1(student x, student y);
bool cmp2(student x, student y);
bool cmp3(student x, student y);
int main()
{
int N, c, i, count = 0;
while (cin >> N >> c&&N)
{
count++;
for (i = 0; i < N; i++)
cin >> stu[i].number >> stu[i].name >> stu[i].mark;;
switch (c){
case 1:sort(stu,stu+N,cmp1); break;
case 2:sort(stu,stu+N,cmp2); break;
case 3:sort(stu,stu+N,cmp3); break;
}
cout << "Case " << count << ":" << endl;
for (i = 0; i < N; i++)
cout << stu[i].number << ' ' << stu[i].name << ' ' << stu[i].mark << endl;
}
return 0;
}
bool cmp1(student x, student y)
{
if (strcmp(x.number, y.number) < 0)//学号递增排序
return true;
else
return false;
}
bool cmp2(student x, student y)
{
if (strcmp(x.name, y.name)<0)
return true;
else if (strcmp(x.name, y.name) == 0)
{
if (strcmp(x.number, y.number) < 0) //姓名非递减排序
return true;
else
return false;
}
else
return false;
}
bool cmp3(student x, student y)
{
if (x.mark < y.mark)
return true;
else if (x.mark == y.mark)
{
if (strcmp(x.number, y.number) < 0) //分数非递减排序
return true;
else
return false;
}
else
return false;
}
hdu1862的更多相关文章
- HDU1862 - EXCEL排序
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1862 解题思路:结构体排序 #include <bits/stdc++.h> using ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
随机推荐
- CSU-1908 The Big Escape
CSU-1908 The Big Escape Description There is a tree-like prison. Expect the root node, each node has ...
- Sql数据表中的关系
- 生产环境下yum的配置
介绍在局域网里面配置本地yum源环境: 在私有云的服务器上配置本地yum源 在局域网中有多台服务器,网段为192.168.10.0/24在其中一台10.11配置本地yum源,其他服务器中的baseur ...
- Java给各个方法记录执行时间
Java给各个方法记录执行时间 long startTime = System.currentTimeMillis();...//要测试时间的方法LoggerFactory.getLogger(Bas ...
- ALICTF2014 EvilAPK4脱壳分析
相关文件可以在下面链接中下载: http://pan.baidu.com/s/1sjpvFy9 1 简述 该apk使用libmobisec.so函数实现对dex的解密还原.真正的dex为assets目 ...
- 在npm当中发布自己的包的方法
首先需要一个注册一个npm账号,注意,必须验证邮箱,不然是无法发布包的!下面是当时的报错 接着在你需要发布的包的文件夹下面打开你的cmd或者其他的命令行输入工具 输入 npm init 初始化你的 ...
- 如何清除全部的NSUserDefaults储存的数据。
今天做项目遇到,如何清除全部的NSUserDefaults储存的数据. 方法1:找到所有的key然后remove掉 代码: [objc] view plain copy /** * 清除所有的存储本地 ...
- jQuery基础 浅析(含基本方法和选择器)
1.jQuery与DOM互相转换 jQuery入库函数:$(document).ready(function(){}) $(function(){}) $(“#btn”):jQuery存储的是DOM对 ...
- 股票交易(bzoj 1855)
Description 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价 ...
- 51Nod 1028 大数乘法 V2
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 分析: FFT/NTT板子题... 代码: NTT板子: #inc ...