Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main(){
- string s;
- cin >> s;
- int stepen_9 = 1;
- int ost = 8;
- int res = 0;
- for (int i = 1; i < s.size(); i++) {
- stepen_9 *= 9;
- res += ost;
- ost *= 9;
- }
- for(int i = 0; i < s.size(); i++) {
- int cifra = s[i] - '0';
- int m = 0;
- if (i == 0) {
- if (cifra <= 6) {
- m = cifra - 1;
- }
- else {
- m = cifra - 2;
- }
- }
- else {
- if (cifra <= 6) {
- m = cifra;
- }
- else {
- m = cifra - 1;
- }
- }
- res += m * stepen_9;
- stepen_9 /= 9;
- }
- cout << res + 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment