Josif_tepe

Untitled

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