fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int getCount(int n)
  5. {
  6. int count = 0;
  7. for (int i = 0; i <= n; i++) {
  8. string s = to_string(i);
  9. for (int j = 0; j < s.size(); j++)
  10. if (s[j] == '2')
  11. count++;
  12. }
  13.  
  14. return count;
  15. }
  16.  
  17. int main() {
  18. cout << getCount(26) << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
10