PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题

Posted 辰曦~文若

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题相关的知识,希望对你有一定的参考价值。

题意:给出n个人的姓名、性别、ID、分数,让你找出其中哪个妹纸分数最高、哪个汉子分数最低、以及他们的差
如果没有妹纸或者汉子,则对应输出Absent,差用NA代替。

就是for一遍找最大最小值,水题

技术分享
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <vector>
#define INF 0x3f3f3f3f
using namespace std;
struct Node{
    char name[15];
    char ID[15];
    int grade;
}male,female,tmp;
int main()
{
    int n;
    char str[10];
    scanf("%d",&n);
    male.grade=INF;
    female.grade=-1;
    for(int i=0;i<n;i++){
        scanf("%s %s %s %d",tmp.name,str,tmp.ID,&tmp.grade);
        if(str[0]==M){
            if(tmp.grade<male.grade){
                strcpy(male.name,tmp.name);
                strcpy(male.ID,tmp.ID);
                male.grade=tmp.grade;
            }
        }
        else{
            if(tmp.grade>female.grade){
                strcpy(female.name,tmp.name);
                strcpy(female.ID,tmp.ID);
                female.grade=tmp.grade;
            }
        }
    }
    bool absent=false;
    if(female.grade!=-1){
        printf("%s %s\n",female.name,female.ID);
    }
    else{
        absent=true;
        printf("Absent\n");
    }
    if(male.grade!=INF){
        printf("%s %s\n",male.name,male.ID);
    }
    else{
        absent=true;
        printf("Absent\n");
    }
    if(absent){
        printf("NA\n");
    }
    else{
        printf("%d\n",female.grade-male.grade);
    }

    return 0;
}
View Code

 


以上是关于PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题的主要内容,如果未能解决你的问题,请参考以下文章