fork download
  1. #include<unordered_map>
  2. #include<algorithm>
  3. #include<string>
  4. bool comp(pair<int,int> a, pair<int,int>b)
  5. {
  6. if(a.second==b.second) return a.first<b.first;
  7. else return a.second>b.second;
  8. }
  9. vector<int> Solution::solve(string A, vector<string> &B) {
  10. unordered_map <string,int> goodvalues;
  11. string s={};
  12. for(int i=0;i<A.size();i++)
  13. {
  14. if(A[i]=='_')
  15. {
  16. goodvalues[s]++;
  17. s = {};
  18. }
  19. else
  20. s.push_back(A[i]);
  21. }
  22. goodvalues[s]++;
  23. vector<int> ans;
  24. vector<pair<int,int> >sortvalues;
  25. for(int i=0;i<B.size();i++)
  26. {
  27. s = B[i];
  28. int value=0;
  29. string word;
  30. for(int j=0;j<s.size();j++)
  31. {
  32. if(s[j]=='_')
  33. {
  34. if(goodvalues[word]==1)
  35. {
  36. value++;
  37. }
  38. word={};
  39. }
  40. else
  41. word.push_back(s[j]);
  42. }
  43. if(goodvalues[word]==1)
  44. {
  45. value++;
  46. }
  47. sortvalues.push_back(make_pair(i,value));
  48. }
  49. sort(sortvalues.begin(),sortvalues.end(),comp);
  50.  
  51. for(auto i:sortvalues)
  52. {
  53. ans.push_back(i.first);
  54. }
  55. return ans;
  56. }
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:11: error: ‘pair’ was not declared in this scope
 bool comp(pair<int,int> a, pair<int,int>b)
           ^~~~
prog.cpp:4:11: note: suggested alternative:
In file included from /usr/include/c++/6/utility:70:0,
                 from /usr/include/c++/6/unordered_map:38,
                 from prog.cpp:1:
/usr/include/c++/6/bits/stl_pair.h:190:12: note:   ‘std::pair’
     struct pair
            ^~~~
prog.cpp:4:16: error: expected primary-expression before ‘int’
 bool comp(pair<int,int> a, pair<int,int>b)
                ^~~
prog.cpp:4:20: error: expected primary-expression before ‘int’
 bool comp(pair<int,int> a, pair<int,int>b)
                    ^~~
prog.cpp:4:28: error: ‘pair’ was not declared in this scope
 bool comp(pair<int,int> a, pair<int,int>b)
                            ^~~~
prog.cpp:4:28: note: suggested alternative:
In file included from /usr/include/c++/6/utility:70:0,
                 from /usr/include/c++/6/unordered_map:38,
                 from prog.cpp:1:
/usr/include/c++/6/bits/stl_pair.h:190:12: note:   ‘std::pair’
     struct pair
            ^~~~
prog.cpp:4:33: error: expected primary-expression before ‘int’
 bool comp(pair<int,int> a, pair<int,int>b)
                                 ^~~
prog.cpp:4:37: error: expected primary-expression before ‘int’
 bool comp(pair<int,int> a, pair<int,int>b)
                                     ^~~
prog.cpp:4:42: error: expression list treated as compound expression in initializer [-fpermissive]
 bool comp(pair<int,int> a, pair<int,int>b)
                                          ^
prog.cpp:9:1: error: ‘vector’ does not name a type
 vector<int> Solution::solve(string A, vector<string> &B) {
 ^~~~~~
stdout
Standard output is empty