简单题目,纯当练手
#include <stdio.h>
#include <string.h>
int bin[32];
char buffer[100];
void init()
{
int i;
for(i=1; i<=31; i++)
{
bin[i] = (1<<i)-1;
}
}
void func()
{
int i, j;
int sum;
sum = 0;
for(i=strlen(buffer)-1,j=1; i>=0; i--,j++)
{
sum += (buffer[i]-'0')*bin[j];
}
printf("%d\n", sum);
}
int main(void)
{
init();
while(1)
{
scanf("%s", &buffer);
if(!strcmp(buffer,"0"))
break;
func();
}
return 0;
}