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;
}

时间: 2024-10-25 13:01:24

PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题的相关文章

PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

1036 Boys vs Girls (25 分) 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 contai

PAT 1036. Boys vs Girls (25)

1036. Boys vs Girls (25) 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 contain

PAT 1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25 分) 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 contai

1036. Boys vs Girls (25)

1036. Boys vs Girls (25) 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 contain

PAT (Advanced Level) 1036. Boys vs Girls (25)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<vector> using namespace std; const int maxn=100000; struct X { string nam

1036 Boys vs Girls (25分)

1. 题目 2. 思路 用vector<node> m, vector<node> f 分别存放女性和男性,后排序比较 3. 注意点 无 4. 代码 #include<cstdio> #include<algorithm> #include<set> #include<map> #include<vector> #include<string> using namespace std; struct stu{

pat1036. Boys vs Girls (25)

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 Spec

PAT 1036 Boys vs Girls[简单]

1036 Boys vs Girls (25 分) 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 contai

1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25 分) 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 contai