题解 | Skew数

Skew数

https://www.nowcoder.com/practice/7b6586ac8f614aafbe2e0896e82ac0c1?tpId=40&tqId=21382&rp=1&difficulty=&judgeStatus=&tags=/question-ranking

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    long long res;
    while (cin >> str) {
        if (str == "0")    break;
        res = 0;
        int n = str.size();
        for (int i = 0; i < n; i++) {
            res += (str[i] - '0') * (pow(2, n - i) - 1);
        }
        cout << res << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

_mos_:我以为手抄报简历就已经很顶了,没想到还有表格简历
点赞 评论 收藏
分享
06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务