題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1193
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <iostream> #include <string> #include <vector> #include <algorithm> #include <map>
using namespace std;
int main(){ string a; string b; while(getline(cin, a)){ getline(cin, b); map<char, int> m; vector<char> ans; int Size = a.length(); for(int i=0; i < Size; ++i){ ++m[a[i]]; } Size = b.length(); for(int i=0; i < Size; ++i){ if(m[b[i]] > 0){ ans.push_back(b[i]); --m[b[i]]; } } sort(ans.begin(), ans.end()); Size = ans.size(); for(int i=0; i < Size; ++i){ cout << ans[i]; } cout << '\n'; } return 0; }
|