A1036 Boys vs Girls (25 分)

#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct student{
    
    
	char name[15];
	char id[15];
	int score;
}m, f, temp;

void init(){
    
    
	m.score = 101;
	f.score = -1;
}

int main(int argc, char** argv) {
    
    
	init();
	int n = 0;
	cin >> n;
	char gender;
	int score;
	while(n--){
    
    
		cin >> temp.name >> gender >> temp.id >> temp.score;
		if(gender == 'M'){
    
    
			if(temp.score < m.score){
    
    
				m = temp; 
			}
		} else {
    
    
			if(temp.score > f.score){
    
    
				f = temp; 
			}
		}
	}
	
	if(f.score == -1){
    
    
		cout << "Absent" << endl;
	} else {
    
    
		cout << f.name << " " << f.id << endl;
	}
	
	if(m.score == 101){
    
    
		cout << "Absent" << endl;
	} else {
    
    
		cout << m.name << " " << m.id << endl;
	}
	
	if(f.score == -1 || m.score == 101){
    
    
		cout << "NA" << endl;
	} else {
    
    
		cout << f.score - m.score;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/alovelypeach/article/details/113828670