- 数的计数
- 2017-07-09 22:21:11 @
扩展如下:(样例)
6->
6,16,26,36->
6,16,26,36,126,136共6个。
再随便编一个吧:
8->
8,18,28,38,48->
8,18,28,38,48,128,138,148,248->
8,18,28,38,48,128,138,148,248,1248->共10个。
#include <stdio.h>
#include <stdlib.h>
//得到数字长度
int getLength(int num){
int length = 0;
while(num/10>0){
num/=10;
length++;
}
return length+1;
}
//得到最新的数
int getNum(int num,int hand,int length){
for(int i=0;i<length;i++){
hand*=10;
}
return hand+num;
}
//得到所有可行的情况
void getTotle(int num,int &totle,int hand){
totle++;
int midNum = hand/2;
for(int i=1;i<=midNum;i++){
int length = getLength(num);
int newNum = getNum(num,i,length);
getTotle(newNum,totle,i);
}
}
int main() {
int num = 0;
scanf("%d",&num);
int totle = 0;
getTotle(num,totle,num);
printf("%d",totle);
return EXIT_SUCCESS;
}
0 条评论
目前还没有评论...