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

      

  • 相关阅读:
    MySQL教程115-MySQL查看触发器
    MySQL教程114-MySQL创建触发器
    MySQL教程113-MySQL流程控制语句
    MySQL教程112-MySQL游标的定义及使用
    MySQL教程111-MySQL定义条件和处理程序
    MySQL教程110-MySQL变量的定义和赋值
    MySQL教程109-MySQL调用存储过程和函数
    MySQL教程108-MySQL存储函数
    mysql 启动关闭流程
    mysql 连接管理工具
  • 原文地址:https://www.cnblogs.com/grglym/p/7738835.html
Copyright © 2011-2022 走看看