PAT(Advanced Level) 1001. A+B Format (20)
2018-03-21 20:31
856 查看
最近开始做PAT,正儿八经地练习代码。程序员真的离不开写代码,更离不开看别人的代码。有时候AC了看看大神的代码,才知道自己的算法是多愚蠢。Github和CSDN的大神是真的强!一个人写代码也没啥意思,也决定学学大神写写刷题记录,增加点儿趣味,谁还没个想做大神的心呢?
以上算是新博客的见面礼,不废话了,滚去写代码!!
内存限制65536 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).InputEach 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.OutputFor 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
以上算是新博客的见面礼,不废话了,滚去写代码!!
1001. A+B Format (20)
时间限制400 ms内存限制65536 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).InputEach 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.OutputFor 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 9Sample Output
-999,991
#include<iostream> #include<cstdlib> using namespace std; void DisplaySum(int n) { int sum[8] = { 0 }; int i = 0; if (0 == n) cout << "0"; if (n < 0) { n = -n; cout << "-"; } while (n) { sum[i] = n % 10; n /= 10; i++; } for (int j = i-1; j >=0; j--) { if (0 == j % 3&&j) cout << sum[j] << ","; else cout << sum[j]; } } int main(void) { int a, b; cin >> a >> b; DisplaySum(a + b); system ("PAUSE"); return 0; }第一个题还是比较容易的,注意数组初始化,不然要出事。
相关文章推荐
- 【PAT (Advanced Level)】1001. A+B Format (20)
- 【c++】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)
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- PAT (Advanced Level) Practise 1001 A+B Format (20)
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- PAT (Advanced Level) Practise - 1001 A+B Format (20)
- 编程题目:PAT(Advanced Level) Practice 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001 A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- 浙大PAT (Advanced Level) Practise 1001 A+B Format (20)
- 【PAT Advanced Level】1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced) 1001. A+B Format (20)
- 【PAT】【Advanced Level】1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)