https://www.nowcoder.com/pat/2/problem/266
吐槽:找到权值公式x[k] = 2*x[k-1] +1,然后先算出来。

#include<cstdio>
#include<cstring>
int x[50];

int main(){
    x[0]=1;
    x[1]=3;
    for(int i=2;i<32;i++){
        x[i] = 2*x[i-1] + 1;
    }
    char str[100];
    while(scanf("%s",str) != EOF){
        int len = strlen(str);
        int sum = 0;
        for(int i = 0; i < len; i++){
            sum += (str[i] - '0')*x[len - 1 - i];
        }
        printf("%d\n",sum);
    }

}