zoukankan      html  css  js  c++  java
  • 1036. Boys vs Girls

    1036. Boys vs Girls (25)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.

    Input Specification:

    Each input file contains one test case. Each case contains a positive integer N, followed by N lines of student information. Each line contains a student's name, gender, ID and grade, separated by a space, where name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

    Output Specification:

    For each test case, output in 3 lines. The first line gives the name and ID of the female student with the highest grade, and the second line gives that of the male student with the lowest grade. The third line gives the difference gradeF-gradeM. If one such kind of student is missing, output "Absent" in the corresponding line, and output "NA" in the third line instead.

    Sample Input 1:

    3
    Joe M Math990112 89
    Mike M CS991301 100
    Mary F EE990830 95
    
    Sample Output 1:
    Mary EE990830
    Joe Math990112
    6
    
    Sample Input 2:
    1
    Jean M AA980920 60
    
    Sample Output 2:
    Absent
    Jean AA980920
    NA
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<stdlib.h>
     4 #include<string.h>
     5 
     6 struct Stu
     7 {
     8     char name[20], id[20];
     9     char gender;
    10     int grade;
    11 };
    12 
    13 int main()
    14 {
    15     Stu highest_f, lowest_m, temp;
    16     highest_f.grade = -1;
    17     lowest_m.grade = 101;
    18     int i, n;
    19     scanf("%d", &n);
    20     for(i = 0; i < n; i++)
    21     {
    22         scanf("%s %c %s %d", temp.name, &temp.gender, temp.id, &temp.grade);
    23         if(temp.gender == 'F' && temp.grade > highest_f.grade)
    24             highest_f = temp;
    25         if(temp.gender == 'M' && temp.grade < lowest_m.grade)
    26             lowest_m = temp;
    27     }
    28     int flag = 1;
    29     if(highest_f.grade < 0)
    30     {
    31         printf("Absent
    ");
    32         flag = 0;
    33     }
    34     else
    35     {
    36         printf("%s %s
    ", highest_f.name, highest_f.id);
    37     }
    38     if(lowest_m.grade > 100)
    39     {
    40         printf("Absent
    ");
    41         flag = 0;
    42     }
    43     else
    44     {
    45         printf("%s %s
    ", lowest_m.name, lowest_m.id);
    46     }
    47     if(flag)
    48         printf("%d
    ", highest_f.grade - lowest_m.grade);
    49     else
    50         printf("NA
    ");
    51     return 0;
    52 }
  • 相关阅读:
    《博客园美化》添加雪花/修改icon
    js获取开始年与结束年之间的年份
    《博客园美化》为您的博客增加一个萌萌的看板娘吧
    JS对比时间大小
    同域名下两个子级域名共享cookie
    input输入框禁止显示历史记录
    C# 操作符 << 与 >>
    如何在IIS上发布网站
    Sql 插入操作时返回当前新增的Id
    JS Cookie操作
  • 原文地址:https://www.cnblogs.com/yomman/p/4269900.html
Copyright © 2011-2022 走看看