整数进制转换
十进制-》任意进制
string ntos(int n, int to)
{
string s;
while (n != 0)
{
int t = n % to;
if (t <= 9) s += t + '0';
else s += t - 10 + 'A';
n /= to;
}
reverse(s.begin(), s.end());
return s;
}
任意进制-》十进制 (字符串 转 数字)
int ston(string s, int base)
{
int num = 0;
for (int i = 0; i < s.size(); i++)
{
char c = s[i];
if (c <= '9') num = num * base + c - '0';
else num = num * base + c - 'A' + 10;
}
return num;
}
stoi函数可以自动去除前导零
y1=stoi(s[0].substr(0,4));