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;
    }
    

      

  • 相关阅读:
    C++ 将对象写入文件 并读取
    IronPython fail to add reference to WebDriver.dll
    How to Capture and Decrypt Lync Server 2010 TLS Traffic Using Microsoft Tools
    .net code injection
    数学系学生应该知道的十个学术网站
    Difference Between Currency Swap and FX Swap
    Swift开源parser
    谈谈我对证券公司一些部门的理解(前、中、后台)[z]
    JDK8记FullGC时候Metaspace内存不会被垃圾回收
    JVM源码分析之JDK8下的僵尸(无法回收)类加载器[z]
  • 原文地址:https://www.cnblogs.com/grglym/p/7738835.html
Copyright © 2011-2022 走看看