Guest User

Untitled

a guest
Dec 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. unordered_map<int, int> storeinhashmap(vector<int>v, int n)
  2. {
  3. vector<int>::iterator it=v.begin();
  4. unordered_map<int,int>h;
  5. int temp;
  6. while(n--)
  7. {
  8. temp = *it;
  9. h.insert(make_pair<int,int>(n,*it));
  10. it++;
  11. }
  12. return h;
  13. }
  14.  
  15.  
  16.  
  17. int main()
  18. {
  19. int t;
  20. cin>>t;
  21. while(t--)
  22. {
  23. int n, x;
  24. cin>>n;
  25. vector<int>v;
  26. readValues(v, n);
  27. cin>>x;
  28. unordered_map<int, int>h = storeinhashmap(v, n);
  29. //char ans = checksumisx(h, n);
  30.  
  31. }
  32. return 0;
  33. }
  34.  
  35. harshit@harshit-5570:~/Desktop/geeksforgeeks$ g++ -std=c++14 key_pair.cpp
  36. key_pair.cpp: In function ‘std::unordered_map<int, int> storeinhashmap(std::vector<int>, int)’:
  37. key_pair.cpp:26:43: error: no matching function for call to ‘make_pair(int&, int&)’
  38. h.insert(make_pair<int,int>(n, *it));
  39. ^
  40. In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
  41. from /usr/include/c++/5/bits/char_traits.h:39,
  42. from /usr/include/c++/5/ios:40,
  43. from /usr/include/c++/5/ostream:38,
  44. from /usr/include/c++/5/iostream:39,
  45. from key_pair.cpp:1:
  46. /usr/include/c++/5/bits/stl_pair.h:276:5: note: candidate: template<class _T1, class _T2> constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&)
  47. make_pair(_T1&& __x, _T2&& __y)
  48. ^
  49. /usr/include/c++/5/bits/stl_pair.h:276:5: note: template argument deduction/substitution failed:
  50. key_pair.cpp:26:43: note: cannot convert ‘n’ (type ‘int’) to type ‘int&&’
  51. h.insert(make_pair<int,int>(n, *it));
Add Comment
Please, Sign In to add comment