题解 | #skew数#

skew数

http://www.nowcoder.com/practice/5928127cc6604129923346e955e75984

#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX 32

int main(void)
{
    char s[MAX];

    while (scanf("%s", s) != EOF)
    {
        long answr = 0;
        int n = strlen(s);
        for (int i = 0; i < n; i++)
        {
            // printf("%d ", s[i] - '0');
            answr += (s[i] - '0') * (pow(2, n - i) - 1);
        }
        // printf("\n");
        printf("%ld\n", answr);
    }

    return 0;
}

全部评论

相关推荐

中电45所 测试开发岗 可以解决北京户口,提供员工宿舍,早 8 晚 5(不过一般会加班到7-8点,周六一般也会去,面试官说的) 硕士
点赞 评论 收藏
转发
7 收藏 评论
分享
牛客网
牛客企业服务