fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool compare(const tuple<char, int>&i, const tuple<char, int>&j)
  5. {
  6. return i.second > j.second;
  7. }
  8.  
  9. int main() {
  10. // your code goes here
  11. string s;
  12. cin>>s;
  13. map<char,int> mp;
  14. for(int i=0;i<s.size();i++){
  15. if(mp.find(s[i]) != mp.end()){
  16. mp[s[i]]+=1;
  17. }
  18. else mp[s[i]]=1;
  19. }
  20. vector<tuple<char,int>> v;
  21. for(map<char,int>::iterator it=mp.begin(); it!=mp.end();it++){
  22. v.push_back(make_tuple(it->first, it->second));
  23. }
  24. sort(v.begin(), v.end(), compare);
  25. for(int i=0;i<v.size();i++){
  26. cout<<v[i][0]<<" "<<v[i][1]<<", ";
  27. }
  28. cout<<endl;
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
ABBAC
compilation info
prog.cpp: In function ‘bool compare(const std::tuple<char, int>&, const std::tuple<char, int>&)’:
prog.cpp:6:14: error: ‘const class std::tuple<char, int>’ has no member named ‘second’
     return i.second > j.second;
              ^~~~~~
prog.cpp:6:25: error: ‘const class std::tuple<char, int>’ has no member named ‘second’
     return i.second > j.second;
                         ^~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:26:13: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::tuple<char, int> > >::value_type {aka std::tuple<char, int>}’ and ‘int’)
   cout<<v[i][0]<<" "<<v[i][1]<<", ";
             ^
prog.cpp:26:27: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::tuple<char, int> > >::value_type {aka std::tuple<char, int>}’ and ‘int’)
   cout<<v[i][0]<<" "<<v[i][1]<<", ";
                           ^
stdout
Standard output is empty