Advertisement
Josif_tepe

Untitled

Nov 14th, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int pogolemi_od_4(int x) {
  4.     if(x == 0) {
  5.         return 0;
  6.     }
  7.     int cifra = x % 10;
  8.     int dodadi = 0;
  9.    
  10.     if(cifra > 4) {
  11.         dodadi = 1;
  12.     }
  13.     return pogolemi_od_4(x / 10) + dodadi;
  14. }
  15. int pomali_od_4(int x) {
  16.     if(x == 0) {
  17.         return 0;
  18.     }
  19.     int cifra = x % 10;
  20.     int dodadi = 0;
  21.     if(cifra <= 4) {
  22.         dodadi = 1;
  23.     }
  24.     return pomali_od_4(x / 10) + dodadi;
  25. }
  26. int rek(int x) {
  27.     if(pogolemi_od_4(x) > pomali_od_4(x)) {
  28.         return 1;
  29.     }
  30.     else {
  31.         return 2;
  32.     }
  33. }
  34. int main () {
  35.  
  36.     int n;
  37.     scanf("%d", &n);
  38.    
  39.     printf("%d\n", rek(n));
  40.  
  41. return 0;
  42.  
  43. }
  44. // rek(123456, 0, 0) = rek(12345, 1, 0) = 2
  45. // rek(12345, 1, 0) = rek(1234, 2, 0) = 2
  46. // rek(1234, 2, 0) = rek(123, 2, 1) = 2
  47. // rek(123, 2, 1) = rek(12, 2, 2) = 2
  48. // rek(12, 2, 2) = rek(1, 2, 3) = 2
  49. // rek(1, 2, 3) = rek(0, 2, 4) = 2
  50. // rek(0, 2, 4) = 2
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement