fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void find(string &s){
  4. int n=s.length();
  5. sort(s.begin(),s.end());
  6. for(int i=0;i<s.length();){
  7. int count=1;
  8. while(i+count<s.length() && s[i]==s[i+count]){
  9. count++;
  10. }
  11. if(count>1){
  12. cout<<"["<<s[i]<<" "<<count<<"]"<<endl;
  13. }
  14. i+=count;
  15. }
  16. }
  17.  
  18. int main() {
  19. // your code goes here
  20. string s="geeksforgeeks";
  21. find(s);
  22.  
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
[e 4]
[g 2]
[k 2]
[s 2]