fork(3) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool dec(const string &a,const string &b)
  4. {
  5. if(a.length()!=b.length())
  6. return a.length()>b.length();
  7. return a>b;
  8. }
  9. int main() {
  10. int n,count=0;
  11. unordered_map<string,vector<string> >hash;
  12. cin>>n;
  13. while(n--)
  14. {
  15. string str;
  16. cin>>str;
  17. int a;
  18. cin>>a;
  19. if(hash.find(str)==hash.end())
  20. count++;
  21. while(a--)
  22. {
  23. string ns;
  24. cin>>ns;
  25. hash[str].push_back(ns);
  26. }
  27. }
  28. cout<<count<<endl;
  29. unordered_map<string,vector<string> >::iterator it;
  30. for(it=hash.begin();it!=hash.end();it++)
  31. {
  32. cout<<it->first;
  33. vector<string>v;
  34. for(int i=0;i<(it->second).size();i++)
  35. {
  36. string temp=(it->second)[i];
  37. v.push_back(temp);
  38. }
  39. sort(v.begin(),v.end(),dec);
  40. bool vis[v.size()];
  41. memset(vis,false,sizeof(vis));
  42. for(int i=0;i<v.size();i++)
  43. {
  44. if(!vis[i])
  45. {
  46. for(int j=i+1;j<v.size();j++)
  47. {
  48. if(v[j]==v[i].substr(v[i].length()-v[j].length(),v[j].length()))
  49. vis[j]=true;
  50. }
  51. cout<<" "<<v[i];
  52. }
  53. }
  54. cout<<endl;
  55. }
  56.  
  57.  
  58. return 0;
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:39:29: error: no matching function for call to ‘sort(std::vector<std::__cxx11::basic_string<char> >::iterator, std::vector<std::__cxx11::basic_string<char> >::iterator, <unresolved overloaded function type>)’
   sort(v.begin(),v.end(),dec);
                             ^
In file included from /usr/include/c++/6/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:65,
                 from prog.cpp:1:
/usr/include/c++/6/bits/stl_algo.h:4697:5: note: candidate: template<class _RAIter> void std::sort(_RAIter, _RAIter)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
     ^~~~
/usr/include/c++/6/bits/stl_algo.h:4697:5: note:   template argument deduction/substitution failed:
prog.cpp:39:29: note:   candidate expects 2 arguments, 3 provided
   sort(v.begin(),v.end(),dec);
                             ^
In file included from /usr/include/c++/6/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:65,
                 from prog.cpp:1:
/usr/include/c++/6/bits/stl_algo.h:4727:5: note: candidate: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
     ^~~~
/usr/include/c++/6/bits/stl_algo.h:4727:5: note:   template argument deduction/substitution failed:
prog.cpp:39:29: note:   couldn't deduce template parameter ‘_Compare’
   sort(v.begin(),v.end(),dec);
                             ^
stdout
Standard output is empty