【思路】:怒刷水题的节奏。。
【AC代码】:
#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstring> using namespace std; #define MAX 1000+2 #define MAX_NAME_NUM 20+2 struct Student { char name[MAX_NAME_NUM+2]; char num[MAX_NAME_NUM+2]; char sex; }; Student student[MAX]; int n = 0; char getSex(char info[]) { int i = 0; for (i = 0; i < n; i++) { if (!strcmp(info, student[i].name)) return student[i].sex; else if (!strcmp(info, student[i].num)) return student[i].sex; } } int main() { //freopen("in.txt", "r", stdin); int i = 0; //input cin >> n; for (i = 0; i < n; i++) { cin >> student[i].name >> student[i].num >> student[i].sex; } //find int m = 0; cin >> m; for (i = 0; i < m; i++) { char sex_a, sex_b; char info_a[MAX_NAME_NUM], info_b[MAX_NAME_NUM]; cin >> info_a >> info_b; sex_a = getSex(info_a); sex_b = getSex(info_b); if (sex_a != sex_b) cout << "Y" << endl; else cout << "N" << endl; } return 0; }
原文地址:http://blog.csdn.net/weijj6608/article/details/44787947