简单题
思路:sprintf 将数字转为字符串,然后新建一个空的字符串然后将逆序统计是否可以被3整除添加0
感觉简单题做的也很慢
https://github.com/haoel/leetcode
https://github.com/lishaohsuai/leetCode
string thousandSeparator(int n) {
char str[100];
sprintf(str,"%d", n);
char strCopy[100];
int j = strlen(str);
int k = 0;
for(int i=0; str[i]!=‘\0‘;i++){
if((j-i) % 3 == 0 && i!=0){
strCopy[k] = ‘.‘;
k++;
}
strCopy[k] = str[i];
k++;
}
strCopy[k] = ‘\0‘;
printf("oldString %s\n", str);
string rlt(strCopy);
return rlt;
}
原文:https://www.cnblogs.com/eat-too-much/p/14259670.html