zoukankan      html  css  js  c++  java
  • 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 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

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    struct Student{
    	char name[11];
    	char id[11];
    	int grade;
    };
    Student m_stu;
    Student f_stu;
    int main(){
    	char name[11];
    	char gender;
    	char id[11];
    	int grade;
    	m_stu.grade=101;
    	f_stu.grade=-1;
    	int n;
    	scanf("%d",&n);
    	int i,j;
    	for(i=0;i<n;i++){
    		getchar();
    		scanf("%s %c %s %d",name,&gender,id,&grade);
    		if(gender == 'M'&&grade<m_stu.grade){
    			strcpy(m_stu.name,name);
    			strcpy(m_stu.id,id);
    			m_stu.grade=grade;
    			//cout<<grade<<endl;
    		}else if(gender == 'F'&&grade>f_stu.grade){
    			strcpy(f_stu.name,name);
    			strcpy(f_stu.id,id);
    			f_stu.grade=grade;
    		}
    	}
    	if(f_stu.grade==-1 && m_stu.grade == 101){
    		printf("Absent
    Absent
    ");
    		printf("NA
    ");
    	}else if(f_stu.grade==-1&&m_stu.grade != 101){
    		printf("Absent
    %s %s
    ",m_stu.name,m_stu.id);
    		printf("NA
    ");
    	}else if(m_stu.grade == 101&&f_stu.grade!=-1){
    		printf("%s %s
    Absent
    ",f_stu.name,f_stu.id);
    		printf("NA
    ");
    	}else {
    		printf("%s %s
    ",f_stu.name,f_stu.id);
    		printf("%s %s
    ",m_stu.name,m_stu.id);
    		printf("%d
    ",f_stu.grade-m_stu.grade);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    sourcenav安装
    vim-addon-manager【转】
    zmq重点
    一个简单的解决方法:word文档打不开,错误提示mso.dll模块错误。
    微软验证码项目 Captcha Code Demo 从 .NET Core 1.1.2升级到2.1.0
    海康设备如何接入萤石开放平台
    ABP 启用多租户实现数据隔离
    Docker 开发者常用操作命令
    .NET Core 深度克隆对象,引用类型的平行世界
    详解 .NET Core 遍历 List 并移除项
  • 原文地址:https://www.cnblogs.com/grglym/p/7738835.html
Copyright © 2011-2022 走看看