fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int numAppearances(int n, int k) {
  5. const int TEN = 10;
  6. int appearances = 0;
  7. while (n >= TEN) {
  8. if(n % (TEN * TEN) == k) {
  9. ++appearances;
  10. }
  11. n /= TEN;
  12. }
  13. return appearances;
  14. }
  15.  
  16. int main() {
  17. int n = 23230236;
  18. int k = 23;
  19. int rez = numAppearances(n, k);
  20. cout << rez;
  21. return 0;
  22. }
  23.  
  24. /*15 3 2025
  25. Se da un numar n si un numar k de 2 cifre. Sa se afle de cate ori apare k in n.
  26. Exemplu: n=232423 k=23 R: 2
  27. */
  28.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
3