Advertisement
Josif_tepe

Untitled

Oct 6th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int k;
  8. int zbir(int broj) {
  9.     if(broj == 0) {
  10.         return 0;
  11.     }
  12.     int cifra = broj % 10;
  13.     int result = 0;
  14.     if(cifra > k) {
  15.         result = zbir(broj / 10) + cifra;
  16.         cout << cifra;
  17.     }
  18.     else {
  19.         result = zbir(broj / 10);
  20.     }
  21.     return result;
  22. }
  23. int main() {
  24.     cin >> k;
  25.     int n;
  26.     cin >> n;
  27.     for(int i = 0; i < n; i++) {
  28.         int broj;
  29.         cin >> broj;
  30.         int result = zbir(broj);
  31.         cout << ":" << result << endl;
  32.        
  33.     }
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement