Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <map>
  6. using namespace std;
  7. int n,m;
  8. vector<string> arr;
  9. map<string, int> maps;
  10. vector<string> result;
  11. int main() {
  12. cin>>n>>m;
  13. for(int i=0; i<n; i++) {
  14. string temp;
  15. cin>>temp;
  16. maps.insert(make_pair(temp, 1));
  17. arr.push_back(temp);
  18. }
  19. for(int i=0; i<m; i++) {
  20. string temp;
  21. cin>>temp;
  22. if(maps[temp]==1) {
  23. maps[temp]++;
  24. } else {
  25. maps[temp]=1;
  26. arr.push_back(temp);
  27. }
  28. }
  29. for(int i=0; i<arr.size(); i++) {
  30. if(maps[arr[i]]==2)
  31. result.push_back(arr[i]);
  32. }
  33. sort(result.begin(),result.end());
  34. cout<<result.size()<<endl;
  35. for(int i=0; i<result.size(); i++)
  36. cout<<result[i]<<endl;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement