pat 1036 Boys vs Girls

1622 단어
너무 간단해서 남학생팀과 여학생팀을 순서대로 나누어 여학생팀 최고점과 남학생팀 최저점을 뽑았다.
AC 코드:
//1036 16:16 - 16:44
#include<stdio.h>
#include<algorithm>
using namespace std;
const int MAXN=1005;
struct student
{
	char name[14];
	char gender;
	char sid[14];
	int grade;
}female[MAXN];
student male[MAXN];
bool cmp(const student &a, const student &b)
{
	return a.grade < b.grade;
}

int main()
{
	int n,i;
	char sname[14],stuid[14];
	char sgender;
	int gra;
	student s;
	int fg=0;
	int num1=0,num2=0;
	//freopen("C:\\Documents and Settings\\Administrator\\  \\input.txt","r",stdin);

	scanf("%d",&n);
	for(i=0;i<n;i++){
		getchar();
		scanf("%s %c %s%d",&s.name,&s.gender,&s.sid,&s.grade);
		if(s.gender=='M'){
			male[num1++]=s;

		} else 
			female[num2++]=s;
	}
	sort(male,male+num1,cmp);
	sort(female,female+num2,cmp);
	if(num2==0){
		printf("Absent
"); fg=1; }else { printf("%s %s
",female[num2-1].name,female[num2-1].sid); } if(num1==0){ printf("Absent
"); fg=1; } else { printf("%s %s
", male[0].name,male[0].sid); } if(fg==1) printf("NA
"); else printf("%d
", female[num2-1].grade-male[0].grade); return 0; }

좋은 웹페이지 즐겨찾기