//开始把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的更多相关文章

  1. HDU1862 - EXCEL排序

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1862 解题思路:结构体排序 #include <bits/stdc++.h> using ...

  2. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. 【Linked List Cycle II】cpp

    题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...

  2. linux常用的日志分析脚本

    linux实用的日志分析脚本 日志分析 随意的tail一个access_log文件,下面是一条经典的访问记录 /Dec/::: +] “GET /query/trendxml/district/tod ...

  3. RESTful-rest_framework应用第二篇(get、post的序列化与反序列化)

    目的是: 利用rest_framework实现对数据库内容的查看get请求(序列化).提交保存数据post请求 (反序列化) rest_framework序列化组件(即查看和) 第一步:基于Djang ...

  4. 【homework week5】初步了解敏捷开发——自由与约束的哲学统一

    “自由与束缚的哲学统一”或许不该放到标题上去,毕竟它只是我灵光一闪的感悟.但这个spark让我感到高中到大学的哲学应该也没有白学,这是让人非常兴奋的一件事. 所以我还是把它放到了标题上. 来谈敏捷软件 ...

  5. 【转】Apache Thrift - 可伸缩的跨语言服务开发框架

    Apache Thrift - 可伸缩的跨语言服务开发框架 Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架.本文将从 Java 开发人员角度详 ...

  6. CodeForces Round #515 DIv.3 F. Yet another 2D Walking

    http://codeforces.com/contest/1066/problem/F Maksim walks on a Cartesian plane. Initially, he stands ...

  7. POJ 1364:King(差分约束)

    题目大意:判断是否存在一个长度为n的序列满足给出的不等关系. 分析: 将序列和转化成用两个前缀和之差来表示即可变为差分约束系统. 需要注意的是不能忘记n要加+1,因为还有一个特殊源点,自己因为n:=n ...

  8. python在windows下UnicodeDecodeError的解决方法

    之前在windows下使用python调用某些模块时都会报错,像这样: C:\Documents and Settings\Administrator>python -m CGIHTTPServ ...

  9. webRTC前世今生

    WebRTC 的前世今生 本文由 rwebrtc 翻译 WebRTC 技术是激烈的开放的 Web 战争中一大突破.-Brendan Eich, inventor of JavaScript 无插件实时 ...

  10. ionic2 解决白屏问题

    ionic2下创建项目后,运行启动页后白屏几秒,解决方案 问题描述 最近在学习过程中发现ionic2项目运行在真机上,启动页后会有3-5秒的白屏时间,用户体验不是太好. 解决过程 查看到了一篇关于这个 ...