北京大学机试 进制转换 Easy

基本思想:

无;

关键点:

无;

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

void charge(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] >= 'A') {
			cnt = cnt * 16 + int(s[i] - 'A') + 10;
		}
		else {
			cnt = cnt * 16 + int(s[i] - '0');
		}
	}
	cout << cnt << endl;
}

int main() {
	string s;
	while (cin >> s) {
		charge(s.substr(2, s.size() - 2));
	}
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12460065.html