ACM PKU 1565 Skew Binary 简单题

ACM PKU 1565 Skew Binary 简单题

http://acm.pku.edu.cn/JudgeOnline/problem?id=1565
Source Code

Problem: 
1565   User: lnmm 
Memory: 64K  Time: 0MS 
Language: C
++   Result: Accepted 

Source Code 
#include
" stdio.h "
#include
" string.h "
void  main()
{
    
int i,k,base[31],sum;
    
char skew[32];
    
base[0]=1;
    
for(i=1;i<31;i++)base[i]=2*base[i-1]+1//递推,将进制基数储存,避免重复计算
    while(1)
    
{
        scanf(
"%s",skew);
        
if(strcmp(skew,"0")==0)break;
        sum
=0;
        k
=strlen(skew);
        
for(i=0;i<strlen(skew);i++)
        
{
            k
--;
            sum
+=(skew[i]-'0')*base[k];
        
        }


    printf(
"%d\n",sum);
    }


}

你可能感兴趣的:(ACM PKU 1565 Skew Binary 简单题)