fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t;
  6. cin>>t;
  7. while(t--){
  8. string s;
  9. cin>>s;
  10. map<char,int> mp;
  11. for(int i=0; i<s.size(); i++){
  12. mp[s[i]]++;
  13. }
  14. string ans;
  15. for(auto x:mp){
  16. ans+=x.first;
  17. ans+=':';
  18. ans+= to_string(x.second);
  19. ans+=" ";
  20. }
  21.  
  22. cout<<ans<<endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 5288KB
stdin
3
hello
mississippii
barambar
stdout
e:1 h:1 l:2 o:1 
i:5 m:1 p:2 s:4 
a:3 b:2 m:1 r:2