题解 | #添加逗号#
添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
long long int a;
cin >> a;
string str(13,' ');
int i = 0;
while (a != 0)
{
int d = a % 10;
a /= 10;
char temp = d + 48;
str[i++] = temp;
if (i % 4 == 3 && a != 0)
str[i++] = ',';
}
for (int j = i - 1; j >= 0; --j)
{
cout << str[j];
}
}
// 64 位输出请用 printf("%lld")
使用最直观的方法,先存进一个str字符串,然后逆序输出,看别人用递归,也是挺好的想法。
C++题解 文章被收录于专栏
记录在牛客网用C++刷题的题解思路
深信服公司福利 851人发布