View Code
-------------------------------------------------------------------------
-------------------------------------------------------------------------
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
char str[20000];
long long int i,sum,len,n,power,j;
while(gets(str)!=NULL)
{
if(str[0]=='0')
break;
else
{
len=strlen(str);
sum=0;
for(i=len,j=0;i>=1;i--,j++)
{
if(str[j]!='0')
{
power=(pow(2,i)-1);
sum=sum+((str[j]-'0')*power);
}
}
printf("%lld\n",sum);
}
}
return 0;
}
No comments:
Post a Comment