UVA 575-Skew Binary

来源:互联网 发布:wind数据库 免费版 编辑:程序博客网 时间:2024/06/05 15:42

UVA 575-Skew Binary

题目大意:按公式计算

解题思路:直接套公式

#include <stdio.h>#include <iostream>#include <math.h>#include <string.h>using namespace std;int main() {    char a[1000];    while(gets(a) && a[0] != '0') {        int n = strlen(a);        long long int s = 0;        for(int i = 0; i < n; i++) {            s = s + (a[i] - '0') * (pow(2, n-i) - 1);        }        printf("%lld\n", s);    }    return 0;}
0 0
原创粉丝点击