本题主要考察边界条件判断,数字取模取余运算。
#include <iostream>
#include <cstdio>
#include <string>
#include<iomanip>
using namespace std;
int main(void)
{
long n,m;
cin >> n >> m;
long ad = n + m;
string s;
if (ad >= 1000000) {
cout << ad / 1000000 << "," << right << setw(3) << setfill('0')<< ad/1000%1000 << "," << right << setw(3) << setfill('0') <<ad % 1000;
}
else if (ad <= -1000000) {
ad = -ad;
cout <<"-"<< ad / 1000000 << "," << right << setw(3) << setfill('0') << ad / 1000 % 1000 << "," << right << setw(3) << setfill('0') << ad % 1000;
}
else if (-1000>=ad ) {
ad = -ad;
cout<<"-"<<ad/1000<<","<< right << setw(3) << setfill('0') << ad % 1000;
}
else if (ad >= 1000) {
cout << ad / 1000 << "," << right << setw(3) << setfill('0') << ad % 1000;
}
else {
cout << ad;
}
}