1036. Boys vs Girls (25)-PAT甲级真题

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

题目大意:给出N个同学的信息,输出女生中的最高分获得者的信息与男生中最低分获得者的信息,并输出他们的分数差。如果不存在女生或者男生,则对应获得者信息处输出Absent,而且差值处输出NA~

分析:用string类型的female和male保存要求的学生的信息,femalescore和malescore处保存男生的最低分和女生的最高分~

一开始设femalescore为最低值-1,malescore为最高值101,最后根据分值是否为-1或者101来判断是否有相应的女生或者男生~

#include <iostream>
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    string female, male;
    int femalescore = -1, malescore = 101;
    for(int i = 0; i < n; i++) {
        string name, sex, num;
        int score;
        cin >> name >> sex >> num;
        scanf("%d", &score);
        if(sex == "F") {
            if(femalescore < score) {
                femalescore = score;
                female = name + " " + num;
            }
        } else if(malescore > score) {
                malescore = score;
                male = name + " " + num;
            }
    }
    if(femalescore != -1)
        cout << female << endl;
    else
        printf("Absent\n");
    if(malescore != 101)
        cout << male << endl;
    else
        printf("Absent\n");
    if(femalescore != -1 && malescore != 101)
        printf("%d", femalescore - malescore);
    else
        printf("NA");
    return 0;
}

 

 

 

 

 

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
1. 智慧社区背景与挑战 随着城市化的快速发展,社区面临健康、安全、邻里关系和服务质量等多方面的挑战。华为技术有限公司提出智慧社区解决方案,旨在通过先进的数字化技术应对这些问题,提升城市社区的生活质量。 2. 技术推动智慧社区发展 技术进步,特别是数字化、无线化、移动化和物联化,为城市社区的智慧化提供了可能。这些技术的应用不仅提高了社区的运行效率,也增强了居民的便利性和安全性。 3. 智慧社区的核心价值 智慧社区承载了智慧城市的核心价值,通过全面信息化处理,实现对城市各个方面的数字网络化管理、服务与决策功能,从而提升社会服务效率,整合社会服务资源。 4. 多层次、全方位的智慧社区服务 智慧社区通过构建和谐、温情、平安和健康四大社区模块,满足社区居民的多层次需求。这些服务模块包括社区医疗、安全监控、情感沟通和健康监测等。 5. 智慧社区技术框架 智慧社区技术框架强调统一平台的建设,设立数据中心,构建基础网络,并通过分层建设,实现平台能力及应用的可持续成长和扩展。 6. 感知统一平台与服务方案 感知统一平台是智慧社区的关键组成部分,通过统一的RFID身份识别和信息管理,实现社区服务的智能化和便捷化。同时,提供社区内外监控、紧急救助服务和便民服务等。 7. 健康社区的构建 健康社区模块专注于为居民提供健康管理服务,通过整合医疗资源和居民接入,实现远程医疗、慢性病管理和紧急救助等功能,推动医疗模式从治疗向预防转变。 8. 平安社区的安全保障 平安社区通过闭路电视监控、防盗报警和紧急求助等技术,保障社区居民的人身和财产安全,实现社区环境的实时监控和智能分析。 9. 温情社区的情感沟通 温情社区着重于建立社区居民间的情感联系,通过组织社区活动、一键呼叫服务和互帮互助平台,增强邻里间的交流和互助。 10. 和谐社区的资源整合 和谐社区作为社会资源的整合协调者,通过统一接入和身份识别,实现社区信息和服务的便捷获取,提升居民生活质量,促进社区和谐。
void Sort_CollegeScore(AllCollege *as) //按学院总分排序(直接插入排序) { int i,j,k; printf("\t|----------------------------------------------------------------|\n"); printf("\t|---- 学院编号\t|学院名字 |男团体总分|女团体总分|总分 |----|\n"); printf("\t|----------------------------------------------------------------|\n"); for (i = 2;i<as->College_num;i++) { as->College[0].boys_score = as->College[i].boys_score; as->College[0].girl_score = as->College[i].girl_score; as->College[0].shool_score = as->College[i].shool_score; as->College[0].College = as->College[i].College; strcpy(as->College[0].College_name,as->College[i].College_name); j = i - 1; while (as->College[0].shool_score < as->College[j].shool_score && j >0) { as->College[j+1].boys_score = as->College[j].boys_score; as->College[j+1].girl_score = as->College[j].girl_score; as->College[j+1].shool_score = as->College[j].shool_score; as->College[j+1].College = as->College[j].College; strcpy(as->College[j+1].College_name,as->College[j].College_name); j--; } as->College[j+1].boys_score = as->College[0].boys_score; as->College[j+1].girl_score = as->College[0].girl_score; as->College[j+1].shool_score = as->College[0].shool_score; as->College[j+1].College = as->College[0].College; strcpy(as->College[j+1].College_name,as->College[0].College_name); } for (k = 2;k<=as->College_num;k++) { printf("\t|---- %-9d|%-8s |%-4d\t|%-10d|%-8d|----|\n",as->College[k].College,as->College[k].College_name,as->College[k].boys_score,as->College[k].girl_score,as->College[k].shool_score); printf("\t|----------------------------------------------------------------|\n"); } printf("\n\n");system("pause"); }
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值