【持续更新】积累在刷题过程中常见的小问题和他们的解决办法
进制转换
将10进制n转化为d进制的数,转化后的每一位储存在数组arr里(倒序)
int len = 0,arr[100];
while(n!=0){
arr[len++] = n%d;
n = n/d;
}
format
output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
即9999999表示为99,999,999
string str = to_string(n);
int leng = str.length();
for(int i = 0;i<leng;i++){
cout<< str[i];
if(str[i] == '-'){
continue;
}
if((i+1) %3 == leng % 3 && i != leng-1){
cout<< ",";
}
}