Advertisement
fahad005

char_frequency.cpp

Jun 26th, 2021
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define mx 100010
  7. #define mod 1000000007
  8. #define inf INT_MAX
  9. #define pi acos(-1)
  10. #define endl '\n'
  11. #define pb push_back
  12. #define debug cout << "OK" << endl
  13. #define fin freopen("input", "r", stdin)
  14. #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  15. //
  16. int main() {
  17.     string str;
  18.     cin >> str;
  19.  
  20.     multimap<ll, char> m;
  21.     multimap<ll, char>::iterator it;
  22.     ll cnt = 1;
  23.  
  24.     for (ll i = 1; i < str.length(); i++) {
  25.         if (str[i] == str[i - 1]) cnt++;
  26.         else {
  27.             m.insert({ cnt, str[i - 1] });
  28.             cnt = 1;
  29.         }
  30.     }
  31.     m.insert({ cnt, str[str.length() - 1] });
  32.     it = m.end();
  33.     it--;
  34.  
  35.     cout << it->second << " -> " << it->first << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement