# PAT 解题报告 1036. Boys vs Girls (25)

### 1036. Boys vs Girls 算法分析：

```#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>

using namespace std;

typedef struct {
char name[20];
char gender[10];
char ID[20];
int flag; //0: undefined
} Record;

Record girl;
Record boy;

int N;
Record curr;
int main(void) {
scanf("%d", &N);
if(0 == N) return 0;
girl.flag = 0;
boy.flag = 0;
while(N--) {
scanf("%s", curr.name);
scanf("%s", curr.gender);
scanf("%s", curr.ID);
curr.flag = 1;
if('M' == curr.gender[0]) {
if(boy.flag) {
memcpy(&boy, &curr, sizeof(Record));
}
else
memcpy(&boy, &curr, sizeof(Record));
}
else {
if(girl.flag) {
memcpy(&girl, &curr, sizeof(Record));
}
else
memcpy(&girl, &curr, sizeof(Record));
}
}
if(girl.flag && boy.flag) {
cout<<girl.name<<" "<<girl.ID<<endl;
cout<<boy.name<<" "<<boy.ID<<endl;
}
else {
if(girl.flag)
cout<<girl.name<<" "<<girl.ID<<endl;
else
cout<<"Absent"<<endl;
if(boy.flag)
cout<<boy.name<<" "<<boy.ID<<endl;
else
cout<<"Absent"<<endl;
cout<<"NA"<<endl;
}
return 0;
}
```

### 1036. Boys vs Girls 注意点：

（全文完，原创文章，转载时请注明作者和出处）

（转载本站文章请注明作者和出处 烟客旅人 sigmainfy — http://www.sigmainfy.com，请勿用于任何商业用途）

Written on December 28, 2013