题解 | #进制转换2#

进制转换2

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

#include<iostream>
#include<vector>
using namespace std;

int main() {
	long long m, n;
	string str;
	while (cin >> m >> n) {
		cin >> str;
		long long input = 0;
		long long temp = 1;
		for (int i = str.size()-1; i >=0 ; i--) {
			if (str[i] >= '0' && str[i] <= '9') {
				input = input + (str[i] - '0') * temp;
				temp = temp * m;
			}
			else {
				input = input + (str[i] -'A'+10) * temp;
				temp = temp * m;
			}
			

		}
		vector<long long> vec;
		while (input != 0) {
			vec.push_back(input % n);
			input = input / n;


		}
		for (int i = vec.size() - 1; i >= 0; i--) {
			cout << vec[i];
		}
		cout << endl;

	}




}

全部评论

相关推荐

東大沒有派對:这是好事啊(峰哥脸
我的秋招日记
点赞 评论 收藏
分享
牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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