数字特征值.c

#include<stdio.h>
#include<math.h>
int main(){
int number,number1=0;
int m=1,n=0;
int x=0;
int a=0;
int temp=0;
int b=0;
int c=0;

scanf("%d",&number);
do{
x = number % 10;//取出右边的最后一位数字 
n++;//记录位数 
if((x % 2 == 0 && n % 2 == 0)||(x % 2 != 0 && n % 2 != 0)){
a = 1;//位数 n和 位数上的数字x奇偶性相同时,记1 
}else{
a = 0;//不同记0 
}
number /= 10;//去掉右边已经去过的数字 
temp = a * m + temp;//得出的二进制数 
b=temp / m % 10;//取出二进制数的最后一位数字 
m=m*10;//个位*1,十位*10,百位*100 
number1 = pow(2,c) * b + number1;//二进制转化为十进制 
c++;//2的几次方从0开始,每次增1 
}while(number > 0);
//printf("%d\n",temp); 
printf("%d",number1);
return 0;

}

例如:

输入:342315

输出:13

猜你喜欢

转载自blog.csdn.net/renjingjingya0429/article/details/80217610