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 broj = 0;
- int stepen_na_9 = 1;
- int ostanati = 8;
- for(int i = 1; i < s.size(); i++) {
- stepen_na_9 *= 9;
- broj += ostanati;
- ostanati *= 9;
- }
- for(int i = 0; i < s.size(); i++) {
- int cifra = s[i] - 48;
- int moznosti = 0;
- if(i == 0) {
- if(cifra <= 6) {
- moznosti = cifra - 1;
- }
- else {
- moznosti = cifra - 2;
- }
- }
- else {
- if(cifra <= 6) {
- moznosti = cifra;
- }
- else {
- moznosti = cifra - 1;
- }
- }
- broj += moznosti * stepen_na_9;
- stepen_na_9 /= 9;
- }
- cout << broj + 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment