Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <map>
- using namespace std;
- int n,m;
- vector<string> arr;
- map<string, int> maps;
- vector<string> result;
- int main() {
- cin>>n>>m;
- for(int i=0; i<n; i++) {
- string temp;
- cin>>temp;
- maps.insert(make_pair(temp, 1));
- arr.push_back(temp);
- }
- for(int i=0; i<m; i++) {
- string temp;
- cin>>temp;
- if(maps[temp]==1) {
- maps[temp]++;
- } else {
- maps[temp]=1;
- arr.push_back(temp);
- }
- }
- for(int i=0; i<arr.size(); i++) {
- if(maps[arr[i]]==2)
- result.push_back(arr[i]);
- }
- sort(result.begin(),result.end());
- cout<<result.size()<<endl;
- for(int i=0; i<result.size(); i++)
- cout<<result[i]<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement