zoukankan      html  css  js  c++  java
  • PAT乙级1015-----德才论 (25分)

    1015 德才论 (25分)

    输入样例:

    14 60 80
    10000001 64 90
    10000002 90 60
    10000011 85 80
    10000003 85 80
    10000004 80 85
    10000005 82 77
    10000006 83 76
    10000007 90 78
    10000008 75 79
    10000009 59 90
    10000010 88 45
    10000012 80 100
    10000013 90 99
    10000014 66 60
    
     

    输出样例:

    12
    10000013 90 99
    10000012 80 100
    10000003 85 80
    10000011 85 80
    10000004 80 85
    10000007 90 78
    10000006 83 76
    10000005 82 77
    10000002 90 60
    10000014 66 60
    10000008 75 79
    10000001 64 90

    思路:
    1.按题目要求分四类人
    2.同类人分高在前,同类同分德分高在前,同类同分同德按准考证降序

    要特别注意:
    1.题目给的及格优秀线60和80要求输入给出,是变量,不要直接设置为60和80
    2.可能会导致测试点234错误的地方(看代码)

    首次通过代码:

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string.h>
     4 int score1,score2;
     5 struct student{
     6     char id[9];
     7     int d_score;
     8     int c_score;
     9 };
    10 
    11 int judge(struct student s1){
    12     if(s1.d_score>=score2&&s1.c_score>=score2) return 1;
    13     else if(s1.d_score>=score2) return 2;
    14     else if(s1.d_score<score2&&s1.c_score<score2&&s1.d_score>=s1.c_score) return 3;
    15     else return 4;
    16 }
    17 
    18 int cmp(const void *a,const void *b){
    19     struct student a1=*(struct student*)a;
    20     struct student b1=*(struct student*)b;
    21     int r1=judge(a1),r2=judge(b1);
    22     int sum1=a1.d_score+a1.c_score;
    23     int sum2=b1.d_score+b1.c_score;
    24     if(r1<r2) return -1;
    25     else if(r1==r2){
    26         if(sum1>sum2) return -1;
    27         else if(sum1==sum2) {
    28             if(a1.d_score>b1.d_score) return -1;
    29             else if(a1.d_score==b1.d_score) {
    30                 return strcmp(a1.id,b1.id);//这里要返回直接返回strcmp(a1.id,b1.id); 因为可能会返回0
    31             }
    32             else return 1;
    33         }
    34         else return 1;
    35     }
    36     else return 1;
    37 }
    38 
    39 int main(){
    40   struct student s1[100005];
    41   int sum;
    42   int num=0;
    43   scanf("%d %d %d",&sum,&score1,&score2);
    44   for(int i=0;i<sum;i++){
    45       struct student s2;
    46       scanf("%s %d %d",s2.id,&s2.d_score,&s2.c_score);
    47       if(s2.d_score>=score1&&s2.c_score>=score1) s1[num++]=s2;
    48   }
    49   qsort(s1,num,sizeof(struct student),cmp);
    50   printf("%d
    ",num);
    51   for(int i=0;i<num;i++){
    52       printf("%s %d %d",s1[i].id,s1[i].d_score,s1[i].c_score);
    53       if(i!=num-1) printf("
    ");
    54   }
    55   return 0;
    56 }
    View Code
  • 相关阅读:
    POJ3662 Telephone Lines (dijkstra+二分)
    Codeforces Round #618 (Div. 2)A. Non-zero
    Codeforces Round #618 (Div. 2)C. Anu Has a Function
    洛谷P1060开心的金明(滚动数组优化)
    洛谷P1006传纸条
    Spring Boot中以代码方式配置Tomcat
    js常用方法总结(以后遇到再进一步总结)
    localStorage的使用
    巧用Ajax的beforeSend 提高用户体验
    四种会话跟踪技术
  • 原文地址:https://www.cnblogs.com/a982961222/p/12404171.html
Copyright © 2011-2022 走看看