Josif_tepe

Untitled

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