UVA 575 - Skew Binary (模拟)

来源:互联网 发布:单片机项目私活 编辑:程序博客网 时间:2024/06/05 16:25

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

#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;}


 

原创粉丝点击