2019-08-27 A1001 A+B Format

非常简单的一道题,只要想明白‘.’应该加到哪个位置之后即可。

#include 
using namespace std;
int main() {
int a, b;
cin >> a >> b;
string s = to_string(a + b);
for (int i = 0; i < s.length(); i++) {
cout << s[i];
if (s[i] == '-') continue;
if ((i + 1) % 3 == s.length() % 3 && i != s.length() - 1) cout << ",";
}
return 0;
}

你可能感兴趣的:(2019-08-27 A1001 A+B Format)