fork download
  1. #include <iostream>
  2. #include <cctype>
  3. int main()
  4. {
  5. char input , last;
  6. int letters = 0 , numbers = 0 , characters = 0 , repeats = 0;
  7.  
  8. while( std::cin >> input && repeats != 3 )
  9. {
  10. ++characters;
  11. if( isalpha(input) ) ++letters;
  12. if( isdigit(input) ) ++numbers;
  13.  
  14. if( characters == 1 ) //First time so you have to set initial value for last char
  15. last = input;
  16.  
  17. if( last == input )
  18. ++repeats;
  19. else
  20. repeats = 1;
  21. }
  22.  
  23. std::cout << "Characters: " << characters << std::endl;
  24. std::cout << "Letters: " << letters << std::endl;
  25. std::cout << "Numbers: " << numbers << std::endl;
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3300KB
stdin
asfd12333
stdout
Characters: 9
Letters: 4
Numbers: 5