fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int TEN = 10;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9. int countDigits = 0, nCpy = n;
  10. if (n == 0) {
  11. countDigits = 1;
  12. }
  13. while (nCpy >= TEN) {
  14. nCpy /= TEN;
  15. }
  16. while (n > 0) {
  17. int digit = n % TEN;
  18. if (digit == nCpy) {
  19. ++countDigits;
  20. }
  21. n /= TEN;
  22. }
  23. cout << countDigits;
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5276KB
stdin
101010
stdout
3