题解 | 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")