-
Description:
-
Enter information about N students and then query them.
-
Input:
-
The first Act N entered, that is, the number of students (n <= 1000)
The next n rows contain information about N students. The information format is as follows: 01 Li Jiangnan 2102 Liu Tang male 2303 Zhang Jun male 1904 Wang na female 19 then input a m (M <= 10000 ), next, there will be m rows, representing M queries. Each row will enter a student ID in the following format: 02030104
-
Output:
-
Output m rows. Each row contains the information of a student corresponding to the query.
If no student information exists, "no answer!" Is output !"
-
Sample input:
-
401 Li Jiang male 2102 Liu Tang male 2303 Zhang Jun male 1904 Wang na female 1950203010403
-
Sample output:
-
02 Liu Tang male 2303 Zhang Jun male 1901 Li Jiang male 2104 Wang na female 1903 Zhang Jun male 19
A simple question.
It is used to practice C ++ map and string usage.
In any case, it's still easy to write without Java.
Learning statement:
1. Map <string, string >:: iterator ITER; // little understanding of C ++.
2、 m.insert(pair<string,string>(id,info));
3. What is the name of the key and value respectively starting with ITER-> first ITER-> second //? To tell the truth, it's really frustrating. No wonder someone says C ++ is rubbish.
4. iter = M. Find (ID );
if(iter != m.end())
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
using namespace std;
int main() {
string id,info,str;
int index,n,M;
map<string,string> m;
map<string,string>:: iterator iter;
while(cin >> n){
cin.ignore();
m.clear();
for(int i=0; i<n; i++){
getline(cin,str);
index = str.find(" ");
id = str.substr(0,index);
info = str.substr(index+1);
m.insert(pair<string,string>(id,info));
}
cin >> M;
for(int i=0; i<M; i++){
cin >> id;
iter = m.find(id);
if(iter != m.end())
cout << iter->first <<" "<<iter->second<<endl;
else
cout<<"No Answer!"<<endl;
}
}
return 0;
}