
- #include
- using namespace std;
- __int128 x;
- int x_;
- string s1;
- int main(){
- stack<int> s;
- while(cin>>s1){
- int len=s1.size();
- for(int i=0;i
- x=x*10+(s1[i]-'0');
- }
- while(x){
- s.push(x%2);
- x=x/2;
- }
- if(s.empty()){
- cout<<0<
- continue;
- }
- while(!s.empty()){
- cout<
top(); - s.pop();
- }
- cout<
- }
- return 0;
- }
2.十六进制转十进制(考虑负数)

- #include
- using namespace std;
- int x;
- string s;
- unordered_map<char,int> hmap;
- int main(){
- hmap['A']=10,hmap['B']=11,hmap['C']=12,hmap['D']=13,hmap['E']=14,hmap['F']=15;
- hmap['a']=10,hmap['b']=11,hmap['c']=12,hmap['d']=13,hmap['e']=14,hmap['f']=15;
- while(cin>>s){
- x=0;
- int end_=2;
- if(s[0]=='-'){cout<<'-';end_=3;}
- int len=s.size();
- for(int i=end_;i
- int temp=0;
- if(s[i]>='0'&&s[i]<='9'){
- temp=s[i]-'0';
- }
- else{
- temp=hmap[s[i]];
- }
- x=x*16+temp;
- //cout<
- }
- cout<
- }
- return 0;
- }
简洁版:(带不带0x都可以转换成功,hex:16,oct:8,dec:10)
- #include
- using namespace std;
- int x;
- int main(){
- while(cin>>hex>>x){
- cout<
- }
- return 0;
- }
- #include
- using namespace std;
- string s;
- int x;
- int main(){
- while(cin>>s){
- x=stoi(s,nullptr,16);
- cout<
- }
- return 0;
- }
-
相关阅读:
JS如何判断文字是否溢出(被ellipsis)?
香港科技大学广州|机器人与自主系统学域博士招生宣讲会—武汉大学专场!!!(暨全额奖学金政策)
3、HTML——注释、转义字符、超链接标签、锚链接、功能性超链接、列表标签、有序列表、无序列表、定义列表
Java基础之《netty(1)—netty介绍》
Vue3 + TS 防抖动
【Java核心技术10】Java数组详解
【分享】Excel“只读方式”的两种模式
【面试题】如何替换项目中的if-else和switch
懒惰型性格分析,如何改变懒惰型性格?
Java复制文件和目录
-
原文地址:https://blog.csdn.net/sweet_Mary/article/details/138187299