Josif_tepe

Untitled

Apr 28th, 2026
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main(){
  5.    
  6.     string s;
  7.     cin >> s;
  8.    
  9.    
  10.     int broj = 0;
  11.     int stepen_na_9 = 1;
  12.     int ostanati = 8;
  13.     for(int i = 1; i < s.size(); i++) {
  14.         stepen_na_9 *= 9;
  15.        
  16.         broj += ostanati;
  17.         ostanati *= 9;
  18.     }
  19.    
  20.    
  21.    
  22.     for(int i = 0; i < s.size(); i++) {
  23.         int cifra = s[i] - 48;
  24.        
  25.         int moznosti = 0;
  26.         if(i == 0) {
  27.             if(cifra <= 6) {
  28.                 moznosti = cifra - 1;
  29.             }
  30.             else {
  31.                 moznosti = cifra - 2;
  32.             }
  33.         }
  34.         else {
  35.             if(cifra <= 6) {
  36.                 moznosti = cifra;
  37.             }
  38.             else {
  39.                 moznosti = cifra - 1;
  40.             }
  41.         }
  42.        
  43.         broj += moznosti * stepen_na_9;
  44.         stepen_na_9 /= 9;
  45.     }
  46.    
  47.     cout << broj + 1 << endl;
  48.        
  49.  
  50.     return 0;
  51. }
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment