[PAT Advanced Level]1001. A+B Format (20)
一开始用了locale,但是提交显示段错误,然后就用了传统方法,转化为字符串处理。#include <iostream> #include <string> #include <sstream> using namespace std; int main() { int a,b; cin>>a>>b; int c = a + b; stringstream strStream; strStream<<c; //int转string的方法! string s = strStream.str(); for(int i = s.size() - 3; i > 0 && s[i - 1] != '-'; i -= 3) s.insert(i, ","); cout<<s<<endl;
补充:软件开发 , C++ ,