Guest User

Untitled

a guest
May 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef pair<string,int> ii;
  4.  
  5. string address_one,address_two;
  6. map<string,pair<int,int> > m1,m2;
  7. vector<ii> ans;
  8.  
  9. int main(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(0);
  12. getline(cin,address_one);
  13. getline(cin,address_two);
  14. //Normalize both addresses
  15. for (int i=0; i<address_one.size(); i++) address_one[i] = tolower(address_one[i]);
  16. for (int i=0; i<address_two.size(); i++) address_two[i] = tolower(address_two[i]);
  17.  
  18. stringstream str1(address_one);
  19. stringstream str2(address_two);
  20.  
  21. int dist = 0;
  22. string w;
  23. while (str1 >> w){
  24. m1[w].first++;
  25. m1[w].second = dist;
  26. dist++;
  27. }
  28. while (str2 >> w){
  29. m2[w].first++;
  30. m2[w].second = dist;
  31. dist++;
  32. }
  33. for (auto it = m1.begin(); it!=m1.end(); it++){
  34. if (it->second.first and m2[it->first].first){
  35. ans.push_back({it->first,abs(it->second.second-m2[it->first].second)});
  36. }
  37. }
  38. cout<<"There are "<<ans.size()<<" words in both addresses\n";
  39. for (int i=0; i<ans.size(); i++){
  40. cout<<i+1<<". "<<ans[i].first<<" contains in both addresses, the absolute distance between the two is "<<ans[i].second<<"\n";
  41. }
  42. }
Add Comment
Please, Sign In to add comment