重点在于用map将id和是否是校友一一对应。
1 #include <iostream> 2 #include <map> 3 using namespace std; 4 5 int main(){ 6 int N, num = 0; 7 string str, old, olb; 8 bool flag = false; 9 cin >> N; 10 map<string,int> isxy; 11 for(int i = 0; i < N; i++){ 12 cin >> str; 13 isxy[str] = 1; 14 if(old.empty() || old.substr(6, 8) > str.substr(6, 8)) old = str; 15 } 16 cin >> N; 17 for(int i = 0; i < N; i++){ 18 cin >> str; 19 if(isxy[str] == 1) num++; 20 if(str == old) flag = true; 21 if(!flag && (olb.empty() || olb.substr(6, 8) > str.substr(6, 8))) olb = str; 22 } 23 if(flag) cout << num << endl << old; 24 else cout << num << endl << olb; 25 return 0; 26 }
浙公网安备 33010602011771号