牛客真题_2017hw_16转10进制

牛客真题_2017hw_16转10进制_第1张图片

#include 
#include 
#include 
using namespace std;
int main(){
	string str;
	while(cin>>str){
		int n = str.size();
//		cout<
		int num = 0;
		for(int i=2;i<n;i++){
//			cout<<"now is "<
			int tmp = 0;
			if('0'<=str[i]&& str[i]<='9'){
				tmp = str[i] - '0';
//				cout<<"among 0---9"<
			}
			else if('A'<=str[i]&& str[i]<='F'){
				tmp = str[i] - 'A' + 10;
//				cout<<"among A--F"<
			}
			else if('a'<=str[i]&& str[i]<='f'){
				tmp = str[i] - 'a' + 10;
//				cout<<"among A--F"<
			}
//			int tmp = str[i] - 'a';
			num *= 16;
			num += tmp;
		}
		cout<<num<<endl;
	}
	return 0;
}

你可能感兴趣的:(算法和数据结构,leetcode,字符串)