PAT 甲级 A1062 (2019/02/15)

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm> // STL    使用相关的函数需要include进来
 4 using namespace std;
 5 struct Stu_info{
 6     char id[10];
 7     int de, cai, sum;
 8     int flag;
 9 }stu[100010];
10 //此函数返回值为bool型,相应的返回 true 或者 false
11 bool cmp(Stu_info a, Stu_info b) {
12     if(a.flag != b.flag) return a.flag < b.flag;
13     else if(a.sum != b.sum) return a.sum > b.sum;
14     else if(a.de != b.de) return a.de > b.de;
15     else return strcmp(a.id, b.id) < 0;
16 }
17 int main(){
18     int n, L, H;
19     scanf("%d%d%d", &n, &L, &H);
20     int m = n;
21     for(int i = 0; i < n; i++) {
22         scanf("%s%d%d", stu[i].id, &stu[i].de, &stu[i].cai);
23         //总分计算
24         stu[i].sum = stu[i].de + stu[i].cai;
25         //判断类别,等地越高,分数越低
26         if(stu[i].de < L || stu[i].cai < L) {
27             stu[i].flag = 5;
28             m--;
29         }
30         else if(stu[i].de >= H && stu[i].cai >= H) stu[i].flag = 1;
31         else if(stu[i].de >= H && stu[i].cai < H) stu[i].flag = 2;
32         else if(stu[i].de >= stu[i].cai) stu[i].flag = 3;
33         else stu[i].flag = 4;
34     }
35     //通过cmp函数返回的值,来进行 (从大到小) 或者 (从小到大)的排序
36     sort(stu, stu + n, cmp);
37     // sort()见sort详解
38     printf("%d\n", m);
39     for(int i = 0; i < m; i++) {
40         printf("%s %d %d\n", stu[i].id, stu[i].de, stu[i].cai);
41     }
42     return 0;
43 }
44
45
46 bool compare(int a,int b){
47     return a<b;     //升序排列,如果改为return a>b,则为降序
48 }
49 int main(){
50     int a[20]={2,4,1,23,5,76,0,43,24,65},i;
51     for(i=0;i<20;i++)
52         printf("%d", a[i]);
53     sort(a,a+20,compare);
54     for(i=0;i<20;i++)
55         printf("%d", a[i]);
56     return 0;
57 }

原文地址:https://www.cnblogs.com/zjsaipplp/p/10415848.html

时间: 2024-07-31 19:09:34

PAT 甲级 A1062 (2019/02/15)的相关文章

【谜客帝国】第147届月思主擂谜会(2019.02.15)

 [谜客帝国]第147届月思主擂谜会(2019.02.15) 主持计分:东东 1.“人在中天日月间”(9笔字)春/月思 [注:面出陈孚<开平即事二首>,“势超大地山河上,-.”] 2. 玉漏声中烟气袅(3字法国奢侈品牌)YSL/月思 3. 双双相念初相爱(2字著名动漫人物)菜菜/月思 4.“数点燕云州外.雪霜威”(足球用语二,4+3)4132.451/月思 [注:面出余文<相见欢>,“登高望断龙旗,未曾归.几度中原北定,梦依稀.朔风乱,胡尘漫,掩斜晖.-.”] 5.“十载同心如一人

PAT 甲级 A1012 (2019/02/15)

1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 struct Stu_info{ 6 int id; //存放 id 的六位整数 7 int score[4]; //存放 C M E A 的(分数)数组 8 }stu[2010]; 9 char course[4] = {'A', 'C', 'M', 'E'}; //将平均分A存在course[0

PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone c

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的PAT甲级证书考试,对网站上的题目进行总结分析: 1001题 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). 计算a+b的值并以一定格式输出其和sum(数字需要

PAT B1015/A1062 Talent and Virtue

PAT B1015/A1062 Talent and Virtue 题目描述: About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.

【谜客帝国】第145届芭比娃娃主擂谜会(2019.01.15)

[谜客帝国]第145届芭比娃娃主擂谜会(2019.01.15) 主持:瓷   计分:默沫 1. 同心十八载,白首居河东(2字2019亚洲杯中国球员)石柯 2. 王朗气极坠地死(3字方位字)骂下马 [注:典据<三国演义>93回,“王朗听罢,气满胸膛,大叫一声,撞死于马下.”] 3. 城头长弓搭白羽(2字宋词人)张翥 4. 重门折屐未曾进(成语)格格不入 [注:重门.折屐,皆为谜格.] 5.“石城古岸头”(2字国家森林公园)圭山 6. 凯撒大帝显露出愤怒(4字<诗经>名句)七月流火 [

【谜客帝国】第148届梦中人主擂谜会(2019.03.15)

[谜客帝国]第148届梦中人主擂谜会(2019.03.15) 主持:瓷    计分:小白 1.夫人囚禁于何处(5字对景点位置咨询语)娘子关在哪 2.找你去战胜排名第二的人(外教练)索尔斯克亚 3.二月里来换新装(莫言小说<蛙>人物)王胆 4.一心除皇上,自然搭上命(科技名词)全息 5.布什更二(货币冠量)一便士 6.“身形婀娜,虽裹在一袭宽大缁衣之中,仍掩不住窈窕娉婷之态”(3字古埃及国王,卷帘格)美尼斯 [注:面为<笑傲江湖>中对仪琳的描写,美尼斯为是埃及第一王朝的开国国王] 7