普通的进制转换
坑点就是字符串可以直接与string相加,不需要使用to——string
进制转化
while (a){ int c=a%13; if(c>=10){ char t=c-10+'A'; s= t+s; } else{ s= to_string(c)+s; } a/=13; } for (int i = s.length(); i < 2; ++i) { s="0"+s; }
#include "iostream" #include "vector" #include "algorithm" using namespace std; string change(int a){ string s; while (a){ int c=a%13; if(c>=10){ char t=c-10+'A'; s= t+s; } else{ s= to_string(c)+s; } a/=13; } for (int i = s.length(); i < 2; ++i) { s="0"+s; } return s; } int main(){ int a,b,c; cin>>a>>b>>c; cout<<"#"<<change(a)<<change(b)<<change(c); return 0; }