您的位置:首页 > 其它

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

2017-04-30 11:33 337 查看
题意:给出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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: