题解 | #进制转换#

进制转换

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

全部评论

相关推荐

这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
你找工作的时候用AI吗?
点赞 评论 收藏
分享
Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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