本文主要是介绍1036. Boys vs Girls (25),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. 原题: https://www.patest.cn/contests/pat-a-practise/1036
2. 思路:
基础数据处理题,读入数据时处理就可以了
3. 源码(已AC):
#include<iostream>
#include<string>
using namespace std;struct Node //学生结构体
{Node(): score(-1) {}string name, id;int score;
};int main(void)
{//freopen("in.txt", "r", stdin);int N;cin >> N;Node male, female;//存储最低分数的男性和最高分数女性的信息male.score = 101;for (int i = 0; i < N; i++){string sn, sid;char gen;int gra;cin >> sn >> gen >> sid >> gra;if(gen == 'F')//女性{if(gra > female.score){female.id = sid;female.name = sn;female.score = gra;}}else//男性{if(gra < male.score){male.id = sid;male.name = sn;male.score = gra;}}}if (female.score > -1)//输出cout << female.name << ' ' << female.id << endl;elsecout << "Absent\n";if (male.score < 101)cout << male.name << ' ' << male.id << endl;elsecout << "Absent\n";if (female.score > -1 && male.score < 101)cout << female.score-male.score << endl;elsecout << "NA" << endl;return 0;
}
这篇关于1036. Boys vs Girls (25)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!