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

    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<cstdio>
     2 #include<iostream>
     3 #include<string.h>
     4 using namespace std;
     5 typedef struct{
     6     char name[11];
     7     char id[11];
     8     char gender;
     9     int grade;
    10 }info;
    11 int main(){
    12     int N, absent = 0;
    13     info boy, girl, temp;
    14     boy.grade = 101;
    15     girl.grade = -1;
    16     scanf("%d", &N);
    17     for(int i = 0; i < N; i++){
    18         scanf("%s %c %s %d", temp.name, &(temp.gender), temp.id, &(temp.grade));
    19         if(temp.gender == 'F'){
    20             if(temp.grade > girl.grade){
    21                 girl = temp;
    22                 strcpy(girl.name, temp.name);
    23                 strcpy(girl.id, temp.id);
    24             }
    25         }else if(temp.gender == 'M'){
    26             if(temp.grade < boy.grade){
    27                 boy = temp;
    28                 strcpy(boy.name, temp.name);
    29                 strcpy(boy.id, temp.id);
    30             }
    31         }
    32     }
    33     if(girl.grade == -1 || boy.grade == 101)
    34         absent = 1;
    35     if(girl.grade == -1)
    36         printf("Absent
    ");
    37     else
    38         printf("%s %s
    ", girl.name, girl.id);
    39     if(boy.grade == 101)
    40         printf("Absent
    ");
    41     else 
    42         printf("%s %s
    ", boy.name, boy.id);
    43     if(absent == 1)
    44         printf("NA
    ");
    45     else
    46         printf("%d", girl.grade - boy.grade);
    47     cin >> N;
    48     return 0;
    49 }
    View Code

    总结:

    1、与1006一样,信息排序模拟,使用struct 结构体记录信息项。尽量边读入边处理,不需要全部存储后再排序。

  • 相关阅读:
    小白学 Python 数据分析(21):pyecharts 好玩的图表(系列终篇)
    小白学 Python 数据分析(20):pyecharts 概述
    小白学 Python 数据分析(19):Matplotlib(四)常用图表(下)
    小白学 Python 数据分析(18):Matplotlib(三)常用图表(上)
    在 ASP.NET Core 程序启动前运行你的代码
    在 ASP.NET Core 项目中使用 MediatR 实现中介者模式
    在 ASP.NET Core 项目中使用 AutoMapper 进行实体映射
    [Vue 牛刀小试]:第十七章
    或许是你应该了解的一些 ASP.NET Core Web API 使用小技巧
    [Vue 牛刀小试]:第十六章
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/8433466.html
Copyright © 2011-2022 走看看