PAT1001
初版
#include<iostream> #include<string> #include<sstream> using namespace std; int main() { int i, j, sum; while(cin>>i>>j) { string out; stringstream ss; sum = i + j; ss<<sum; ss>>out; int len = out.length(); int remain = len % 3; string _out; if(remain != 0) { for(int i = 0; i < remain; i++) { _out = _out + out[i]; } if(len - remain != 0 && out[remain - 1] != '-') { _out += ','; } } int num = 0; for(int i = remain; i < len; i++) { if(num == 3) { _out += ','; num = 0; } _out += out[i]; num++; } cout<<_out<<endl; } return 0;
修改版晚点给