标签:rod string 十进制 i++ dig strrev for rev pre
int conver2(int n, int radix) {
string s = to_string(n);
int sum = 0;
for(int i=0; i<s.length(); i++) {
int num = isdigit(s[i])?s[i]-'0':s[i]-'a'+10;
sum += num*pow(radix,s.length()-1-i);
}
return sum;
}
int conver3(int n, int radix){
int y=0,product=1;
while(n!=0){
y=y+(n%10)*product;
n=n/10;
product=product*radix;
}
return y;
}
int conver(int n, int radix) {
char res[111],num=0;
do {
res[num++] = n%radix+'0';
n/=radix;
} while(n!=0);
// 反转方法一:
// string ress = res;
// reverse(ress.begin(),ress.end());
// 反转方法二:
strrev(res);
return stoi(res);
}
标签:rod string 十进制 i++ dig strrev for rev pre
原文地址:https://www.cnblogs.com/houzm/p/12266243.html