Josif_tepe

Untitled

Apr 28th, 2026
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main(){
  5.    
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int niza[11];
  10.     int power = 1;
  11.     int broj_na_cifri = 0;
  12.     int pom = 0;
  13.     while(n > 0) {
  14.         int cifra = n % 10;
  15.         pom = (pom * 10) + cifra;
  16.         n /= 10;
  17.         broj_na_cifri++;
  18.         power *= 9;
  19.     }
  20.     power /= 9;
  21.    
  22.     int j = 0;
  23.     while(pom > 0) {
  24.         int cifra = pom % 10;
  25.         niza[j] = cifra;
  26.         j++;
  27.         pom /= 10;
  28.     }
  29.    
  30.     int broj = 0;
  31.     int zbir = 0;
  32.     int stepen = 8;
  33.     for(int i = 0; i < broj_na_cifri; i++) {
  34.         int moznosti = 0;
  35.        
  36.         if(i == 0) {
  37.             if(niza[i] <= 6) {
  38.                 moznosti = niza[i] - 1;
  39.             }
  40.             else {
  41.                 moznosti = niza[i] - 2;
  42.             }
  43.         }
  44.         else {
  45.             if(niza[i] <= 6) {
  46.                 moznosti = niza[i];
  47.             }
  48.             else {
  49.                 moznosti = niza[i] - 1;
  50.             }
  51.             zbir += stepen;
  52.             stepen *= 9;
  53.         }
  54.        
  55.         broj += moznosti * power;
  56.         power /= 9;
  57.     }
  58.    
  59.     cout << broj + zbir + 1 << endl;
  60.  
  61.     return 0;
  62. }
  63.  
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment