日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【PAT】A1028 List Sorting

發布時間:2025/3/20 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【PAT】A1028 List Sorting 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Input Specification:

Each input file contains one test case. For each case, the first line contains two integers?N?(≤10?5??) and?C, where?N?is the number of records and?C?is the column that you are supposed to sort the recor1028?List Sortingds with. Then?N?lines follow, each contains a record of a student. A student's record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).

Output Specification:

For each test case, output the sorting result in?N?lines. That is, if?C?= 1 then the records must be sorted in increasing order according to ID's; if?C?= 2 then the records must be sorted in non-decreasing order according to names; and if?C?= 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID's in increasing order.

Sample Input 1:

3 1 000007 James 85 000010 Amy 90 000001 Zoe 60

Sample Output 1:

000001 Zoe 60 000007 James 85 000010 Amy 90

Sample Input 2:

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

Sample Output 2:

000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60

Sample Input 3:

4 3 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 90

Sample Output 3:

000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90

解題思路:

  • 理解題意:給出一組數據,根據第一行給出的兩個數,第一個數表示有多少行數據,第二個數是按多少列排序
  • 本段代碼分為3段:首先,根據題意輸入數據,其次,根據題意用不同的排序函數排序;最后輸出數據
  • 總結:本題十分簡單,理解即可,只要根據不同的要求做不同的排序即可
  • 代碼:

    #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct stu{int id;char name[9];int grade; }s[100010];bool cmp1(stu a,stu b){ return a.id<b.id; } bool cmp2(stu a,stu b){int s= strcmp(a.name,b.name);if(s!=0) return s<0;else return a.id<b.id; }bool cmp3(stu a,stu b){if(a.grade!=b.grade) return a.grade<b.grade;else return a.id<b.id; } int main(){int N,C;scanf("%d%d",&N,&C);for(int i=0;i<N;i++){scanf("%d",&s[i].id);scanf("%s %d",s[i].name,&s[i].grade);}if(C==1) sort(s,s+N,cmp1);else if(C==2) sort(s,s+N,cmp2);else sort(s,s+N,cmp3);for(int i=0;i<N;i++){printf("%06d %s %d\n",s[i].id,s[i].name,s[i].grade);}return 0; }

    ?

    總結

    以上是生活随笔為你收集整理的【PAT】A1028 List Sorting的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 可以免费看的av网站 | 蜜桃精品噜噜噜成人av | 久久久久久国产精品日本 | 先锋影音色| 日韩欧美一区二 | 日韩一区二区三区视频在线 | 日韩成人激情视频 | 黄色在线网 | 亚洲精品小视频 | 免费黄色小视频在线观看 | 天天草天天射 | 午夜日韩在线观看 | 一区二区三区在线电影 | 超级黄色录像 | 伊人青青草原 | 爱爱视频网 | 日日射视频 | 狠狠操欧美| 伊伊成人网 | 精品综合在线 | 久久青青 | 性欧美在线 | 最新av在线 | 黄色777| 久草视频免费播放 | 欧美精品欧美精品系列 | 久久刺激 | 一区二区三区国产 | 欧美视频精品在线 | 久久99草| 98精品国产 | 中文字幕一区二区三区精华液 | 欧美性另类 | 成人欧美视频在线观看 | 久久怡红院| 四虎4hu| av资源站最新av | 91激情视频在线观看 | 国产噜噜噜噜噜久久久久久久久 | 粉嫩aⅴ一区二区三区四区五区 | 日韩激情小视频 | 国产精品高潮呻吟久久 | 欧美日韩在线视频一区二区 | av有码在线观看 | 成人一级黄色 | 日本在线 | 免费 成 人 黄 色 | 久久人妻少妇嫩草av蜜桃 | 91欧美日韩| 亚洲日批| 国产一区99| 四虎精品欧美一区二区免费 | 欧美综合日韩 | 一区二区三区四区av | 欧美裸体精品 | 中文字幕一区二区三区日韩精品 | 亚洲欧美一二三 | 97人妻精品一区二区三区软件 | 国产视频一二三四区 | 国产成人精品一区二区在线小狼 | 六月婷婷久久 | 午夜激情欧美 | 亚洲顶级毛片 | 日韩激情小说 | 日韩中文字幕在线观看 | caopeng视频 | 男人操女人的网站 | 在线观看免费成人 | 国产白浆在线 | 国产日产精品一区二区三区四区 | 亚洲高清网| 成人av网站免费 | 一区二区精品视频在线观看 | 99久久久无码国产 | 三上悠亚在线一区 | 综合色av | 中文字幕一区二区在线观看视频 | 国产性生活 | 天天插天天搞 | 国产免费一区二区三区网站免费 | 青青免费在线视频 | 欧美一区在线看 | 欧美性受黑人性爽 | 三级黄色在线视频 | 青青在线视频 | 精品+无码+在线观看 | 91久久国产综合久久91 | 日本女教师电影 | 浪漫樱花在线观看高清动漫 | 久久不卡日韩美女 | 朝鲜黄色片 | 免费观看成人在线视频 | 大桥未久av在线播放 | 美女bb视频 | 日日操夜夜草 | 91在线观看视频网站 | www.色就是色.com| 一个色综合导航 | 青青操视频在线观看 |