fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool samedigits( int value )
  5. {
  6. const int digit = value % 10;
  7.  
  8. while( value )
  9. {
  10. if( value % 10 != digit ) return false;
  11. value /= 10;
  12. }
  13. return true;
  14. }
  15.  
  16. int main() {
  17. // your code goes here
  18.  
  19. cout << boolalpha;
  20. cout << samedigits( 1111111 ) << endl;
  21. cout << samedigits( 123 ) << endl;
  22. cout << samedigits( 22222 ) << endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
true
false
true