题解 | #进制转换#

进制转换

https://www.nowcoder.com/practice/deb19498bc644f53a6a99905ef5ee01d

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <vector>

using namespace std;

int CharToInt06401(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	else {
		return c - 'A' + 10;
	}
}

int main() {
	string str;
	while (getline(cin, str)) {
		str = str.substr(2);
		//printf("%s\n", str.c_str());
		double number = 0;
		for (unsigned int i = 0; i < str.size(); ++i) { //16 进制 转 10 进制
			number *= 16;
			number += CharToInt06401(str[i]);
		}
		printf("%.0lf\n", number);
	}
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 18:05
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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