Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
324770 王栎州 【C6-3】十六进制转换 C++ 通过 100 2 MS 268 KB 545 2025-05-31 14:42:47

Tests(3/3):


#include<bits/stdc++.h> using namespace std; int n,a,sum=0; int main(){ string s; cin>>s; if(s=="0"){cout<<0; return 0;} int a; string h,x=""; for(int i=0;i<s.size();i++){ h=""; if(s[i]<='9'){ a=s[i]-'0'; }else{ a=s[i]-'A'+10; } for(int j=1;j<=4;j++){ h=char(a%2+'0')+h; a=a/2; }x+=h; } while(x[0]=='0'){ x.erase(0,1);} while((x.size()%3!=0)){ x='0'+x; } int l=x.size(); for(int i=0;i<=l-2;i=i+3){ n=(x[i]-'0')*4+(x[i+1]-'0')*2+(x[i+2]-'0')*1; cout<<n; } return 0; }


测评信息: