fork download
  1. #include <map>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. int main() {
  7. std :: map < char , size_t > collection ;
  8. std :: string str ;
  9. std :: cout << "Input string: " << std :: endl ;
  10. std :: cout.flush ( ) ;
  11. std :: getline ( std :: cin , str ) ;
  12. for ( std :: string :: const_iterator it = str.begin ( ) , itEnd = str.end ( ) ; it != itEnd ; ++it ) {
  13. collection [ * it ] += 1 ;
  14. }
  15. for ( std :: map < char , size_t > :: const_iterator it = collection.begin ( ) , itEnd = collection.end ( ) ; it != itEnd ; ++it ) {
  16. std :: cout << std :: setw ( 5 ) << std :: setfill ( ' ' ) << std :: left << it -> first
  17. << std :: setw ( it -> second ) << std :: setfill ( '#' ) << std :: left << "" << std :: endl ;
  18. }
  19. }
Success #stdin #stdout 0s 3480KB
stdin
my name is Boris
stdout
Input string: 
     ###
B    #
a    #
e    #
i    ##
m    ##
n    #
o    #
r    #
s    ##
y    #