###### tags: `CPE` # *2022/05/24 CPE_03* ## 題目:  > *提示:cin>>跟getline()同時使用,中間要用getchar(),且使用getchar()要include cstdio * ``` #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int num_1, num_2;//Pair map <string, string>index; map <string, string>::iterator index_pointer; cin >> num_1; getchar(); for (int i = 0; i < num_1; i++) { string str1, str2; getline(cin, str1); getline(cin, str2); index[str1] = str2; } cin >> num_2; getchar(); for (int j = 0; j < num_2; j++) { string str3; getline(cin, str3); cout << index[str3] << endl; } /*這裡是額外補充如何回朔所有在map中的data*/ /*Map 的輸出會依照Key(First)的順序排序*/ for (index_pointer = index.begin(); index_pointer != index.end() ;index_pointer++) { cout << "Line_1\t" << index_pointer->first << "Line_2\t" << index_pointer->second << endl; } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up