Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main(){
- int n;
- cin >> n;
- int niza[11];
- int power = 1;
- int broj_na_cifri = 0;
- int pom = 0;
- while(n > 0) {
- int cifra = n % 10;
- pom = (pom * 10) + cifra;
- n /= 10;
- broj_na_cifri++;
- power *= 9;
- }
- power /= 9;
- int j = 0;
- while(pom > 0) {
- int cifra = pom % 10;
- niza[j] = cifra;
- j++;
- pom /= 10;
- }
- int broj = 0;
- int zbir = 0;
- int stepen = 8;
- for(int i = 0; i < broj_na_cifri; i++) {
- int moznosti = 0;
- if(i == 0) {
- if(niza[i] <= 6) {
- moznosti = niza[i] - 1;
- }
- else {
- moznosti = niza[i] - 2;
- }
- }
- else {
- if(niza[i] <= 6) {
- moznosti = niza[i];
- }
- else {
- moznosti = niza[i] - 1;
- }
- zbir += stepen;
- stepen *= 9;
- }
- broj += moznosti * power;
- power /= 9;
- }
- cout << broj + zbir + 1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment