Advertisement
Josif_tepe

Untitled

Jan 20th, 2023
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <algorithm>
  5. #include <set>
  6. #include <cstring>
  7. using namespace std;
  8.  
  9. int sledna_vrednost(int broj) {
  10.     int tmp = broj;
  11.     int sum = 0;
  12.    
  13.     while(tmp > 0) {
  14.         sum += tmp % 10;
  15.         tmp /= 10;
  16.     }
  17.     return broj + sum;
  18. }
  19.  
  20. int main() {
  21.    
  22.     int potok;
  23.     cin >> potok;
  24.    
  25.     int potok1 = 1;
  26.     int potok3 = 3;
  27.     int potok9 = 9;
  28.    
  29.     while(potok != potok1 and potok != potok3 and potok != potok9) {
  30.        
  31.         while(potok1 < potok) {
  32.             potok1 = sledna_vrednost(potok1);
  33.         }
  34.         while(potok3 < potok) {
  35.             potok3 = sledna_vrednost(potok3);
  36.         }
  37.         while(potok9 < potok) {
  38.             potok9 = sledna_vrednost(potok9);
  39.         }
  40.         if(potok != potok1 and potok != potok3 and potok != potok9) {
  41.             potok = sledna_vrednost(potok);
  42.         }
  43.     }
  44.    
  45.     if(potok == potok1) {
  46.         cout << 1 << " ";
  47.     }
  48.     else if(potok == potok3) {
  49.         cout << 3 << " ";
  50.     }
  51.     else {
  52.         cout << 9 << " ";
  53.     }
  54.     cout << potok << endl;
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement