65,211
社区成员
发帖
与我相关
我的任务
分享
#pragma warning(disable:4786)
#include <iostream>
#include <string>
using namespace std;
int main()
{
long a;
cout << "input a number: ";
cin >> a;
char s[20];
string str;
itoa(a,s,10); //这里就是将数字转换成10进制数
str = s;
//string::iterator it;
for(string::size_type pos = str.size()-1, n = 0; pos >= 1; pos--, n++)
{
if(n != 0 && n % 2 == 0)
{
str.insert(pos, ",");
n = -1;
}
cout << str << endl;
}
cout << str << endl;
return 0;
}