题解 | #skew数#

skew数

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

//土尔逊Torson 编写于2023/4/18
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdarg>
#include <string>
#include <stdlib.h>

using namespace std;

int main() {
	string str1;
	while (cin >> str1) {
		int answer = 0;
		for (int i = 0, j = str1.size(); i < str1.size(), 0 < j; ++i, --j) {
			answer += (str1[i] - '0') * ((2 << (j-1)) - 1);
			//printf("str1[%d] - '0' = %d\n", i, str1[i]-'0');
			//printf("2^%d = %d\n", j,2 ^ j);
			//printf("answer[%d] = %d\n", i, answer);
		}

		printf("%d\n", answer);
	}
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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