UVA 575 - Skew Binary (模拟)

        汝佳哥把这道题归为数论。按照题中的计算步骤,直接模拟就过了。

#include <stdio.h>
#include <math.h>
#include <string.h>

int main() {
    char str[50];

    while (scanf("%s", str) && str[0]!='0') {
        int len = strlen(str);
        int res = 0;

        for (int i=0; i<len; i++) {
            int tmp = str[i] - '0';
            res += tmp * ((int)(pow(2, len-i)+0.1) - 1);
        }

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

    return 0;
}


 

posted @ 2013-01-26 22:22  zcube  阅读(155)  评论(0编辑  收藏  举报