Problem description, the administrator is a single dog, in the order of a sequence of numbers, see 1 is uncomfortable, so every 1 on the Carry
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 ... 100 101 102) 103 104
Administrator's record:
If it contains 0 cases
0 2 3 4 5 6 7 8 9 20 22 23 24 .... 99 200 202
Input: 1
Output: 2
Input: 11
Output: 23
#include <stdio.h>#include<string.h>Charstr[ +];//Input Stringintstart[ +],ans[ +],res[ +];//dividend, quotient, remainder//pre-and post-conversion input systemConst intOldbase =Ten;Const intNewbase =9;voidChange () {//Restore individual digits to digital form intI,len =strlen (str); start[0] =Len; for(i=1; i<= len;i++) { if(str[i-1] >='0'&& str[i-1] <='9') {Start[i]= str[i-1] -'0'; } } }voidsolve () {memset (res,0,sizeof(res));//remainder is initialized to null inty,i,j; //modulus n Take the remainder method, (the general rule is the first surplus is low, the remainder is high) while(start[0] >=1) {//as long as the dividend is still greater than or equal to 1, then continue to "modulo 2 take the remainder"y=0; I=1; ans[0]=start[0]; // while(I <= start[0]) {y= y * oldbase +Start[i]; Ans[i+ +] = y/newbase; Y%=newbase; } res[++res[0]] = y;//The remainder of this round of operationsi =1; //to the starting point of the next round of business while((i<=ans[0]) && (ans[i]==0)) i++; //clear this round of use of the dividendmemset (Start,0,sizeof(start)); //The quotient of this round becomes the next round of dividend for(j = i;j <= ans[0];j++) start[++start[0]] =Ans[j]; memset (ans,0,sizeof(ans));//clear this round of quotient, prepare for the next round of operations } }voidoutput () {//reverse output from high to low inti; intnum[9]={0,2,3,4,5,6,7,8,9}; for(i = res[0];i >=1;--i) {printf ("%d", Num[res[i]]); } printf ("\ n"); }intMain () {scanf ("%s", str); Change (); Solve (); Output (); return 0;}
Summary of the problem, personal thinking, in fact, this is a number of the conversion problem, in the series only, 0,2,3,4,5,6,7,8,9 that is only 9 bits,
This is a 10 binary conversion to 9 binary problem, we set up an array num[9]; corresponding input 0 to 9, then the problem is reduced to a large number divided by the number of digits!
The problem is simple. A large number of conversions can be made.
The sequence does not contain 1, the number containing 1 is removed (the administrator does not like the ranking problem)