【c++】PAT (Advanced Level) 1001. A+B Format (20)
2014-02-21 19:01
369 查看
1001. A+B Format (20)
时间限制400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input
-1000000 9
Sample Output
-999,991
测试点某个 如果直接输出数字 像 0 就不会显示3个0,而是显示1个0;
//Artemis #include<iostream> #include<vector> #include<algorithm> #include<iomanip> using namespace std; void print(int a){ cout<<","<<setfill('0')<<setw(3)<<a; } int main(){ int a,b; while(cin>>a>>b){ int c; c=a+b; //cout<<c<<endl; vector <int> cc; while(c/1000!=0){//超过三位数 int m2; m2=c%1000; c=c/1000; if(m2<0){ m2=-m2; } cc.insert(cc.begin(),m2); } cout<<c; for_each(cc.begin(),cc.end(),print); } return 0; }
相关文章推荐
- PAT (Advanced Level) 1001. A+B Format (20) 解题报告
- 【PAT (Advanced Level)】1001. A+B Format (20)
- PAT(Advanced Level) 1001. A+B Format (20)
- PAT (Advanced Level) 1001. A+B Format (20) 字符串每三位添加逗号,stack辅助
- PAT (Advanced Level) 1001. A+B Format (20)
- PAT (Advanced Level) Practise - 1001 A+B Format (20)
- 【c++】PAT (Advanced Level)1011. World Cup Betting (20)
- 浙大PAT (Advanced Level) Practise 1001 A+B Format (20)
- 【c++】PAT(advanced level)1058. A+B in Hogwarts (20)
- 【C++】PAT(advanced level)1065. A+B and C (64bit) (20)
- 【PAT Advanced Level】1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- 【C++】PAT(advanced level)1050. String Subtraction (20)
- PAT (Advanced) 1001. A+B Format (20)
- 【PAT】【Advanced Level】1001. A+B Format (20)
- 【c++】PAT (Advanced Level)1027. Colors in Mars (20)
- 【C++】PAT(advanced level)1042. Shuffling Machine (20)
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- 【c++】PAT (Advanced Level)1008. Elevator (20)