char * thousandSeparator(int n) {
if (n == 0) {
return "0";
}
char *result = calloc(20, sizeof(char));
int i = 0, j = 0;
int temp = n;
while (temp != 0) {
if (j % 3 == 0 && j != 0) {
result[i] = '.';
i++;
}
result[i] = (temp % 10) + 48;
i++;
j++;
temp /= 10;
}
int k = strlen(result);
for (int i = 0; i < k / 2; i++) {
int temp = result[i];
result[i] = result[k - i - 1];
result[k - i - 1] = temp;
}
return result;
}
力扣经典题:千位分隔数
最新推荐文章于 2024-07-25 21:13:04 发布