zoukankan      html  css  js  c++  java
  • 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
    ",female.name,female.ID);
        }
        else{
            absent=true;
            printf("Absent
    ");
        }
        if(male.grade!=INF){
            printf("%s %s
    ",male.name,male.ID);
        }
        else{
            absent=true;
            printf("Absent
    ");
        }
        if(absent){
            printf("NA
    ");
        }
        else{
            printf("%d
    ",female.grade-male.grade);
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    maxscript批量设置摄像机并保存渲染图
    约德尔测试
    团队作业-项目答辩
    团队作业2
    团队作业2
    软件工程-团队作业1
    java HmacMd5 Hmacsha1 hmacsha256加密
    centos7 搭建FTP
    windows相关
    如何在CentOS 7上安装Memcached(缓存服务器)
  • 原文地址:https://www.cnblogs.com/chenxiwenruo/p/6789114.html
Copyright © 2011-2022 走看看