博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PTA模拟EXCEL排序c++版——山东科技大学
阅读量:4032 次
发布时间:2019-05-24

本文共 882 字,大约阅读时间需要 2 分钟。

题目:

Excel可以对一组纪录按任意指定列排序。现请编写程序实现类似功能。
输入格式:
输入的第一行包含两个正整数N(≤1e5​​) 和C,其中N是纪录的条数,C是指定排序的列号。之后有 N行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,保证没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩([0, 100]内的整数)组成,相邻属性用1个空格隔开。
输出格式:
在N行中输出按要求排序后的结果,即:当C=1时,按学号递增排序;当C=2时,按姓名的非递减字典序排序;当C=3时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。
输入样例:

3 1000007 James 85000010 Amy 90000001 Zoe 60

输出样例:

000001 Zoe 60000007 James 85000010 Amy 90

又是一道用快排投机取巧的水题。

#include
using namespace std;struct student{
string number; string name; int point;}stu[100005];int n,c;bool cmp1(student s1,student s2){
return s1.number
>n>>c; for(int i=0;i
>stu[i].number>>stu[i].name>>stu[i].point; } if(c==1) sort(stu,stu+n,cmp1); if(c==2) sort(stu,stu+n,cmp2); if(c==3) sort(stu,stu+n,cmp3); for(int i=0;i

每天进步一点点,十天进步十点点,加油!

更多PTA代码请到我的博客里参考

ps:代码仅供参考,请勿抄袭

转载地址:http://elqbi.baihongyu.com/

你可能感兴趣的文章
机器学习实战之决策树(一)
查看>>
[LeetCode By Python] 2 Add Two Number
查看>>
python 中的 if __name__=='__main__' 作用
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>