文章

26

粉丝

0

获赞

13

访问

1.9k

头像
进制转换2 题解:C++ 懒人写法
P1259 北京大学机试题
发布于2025年6月25日 19:11
阅读数 66

#include<bits/stdc++.h>
using namespace std;

int main(){
	string s;
	while(cin>>s){
		int res=0,m;
		for(int i=s.length()-1;i>=2;i--){
			m=s[i]-'0';
			if(s[i]=='A'){
				m=10;
			}else if(s[i]=='B'){
				m=11;
			}else if(s[i]=='C'){
				m=12;
			}else if(s[i]=='D'){
				m=13;
			}else if(s[i]=='E'){
				m=14;
			}else if(s[i]=='F'){
				m=15;
			}
			res+=m*pow(16,s.length()-1-i);
		}
		cout<<res<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发