PAT A 1001 A+B Format
2016-11-09 08:31
134 查看
https://www.patest.cn/contests/pat-a-practise/1001
格式化输出A+B
从后往前,三个打一个逗号
然后sprintf到s
对s从后往前加逗号
然后输出
Description
输入A,B格式化输出A+B
从后往前,三个打一个逗号
Algorithm
算出A+B=C然后sprintf到s
对s从后往前加逗号
然后输出
Code
#define LOG(x) cout << #x << " = " << (x) << endl #define PRINTLN(x) cout << (x) << endl #define MEM(x, y) memset((x), (y), sizeof((x))) #include <bits/stdc++.h> using namespace std; const double PI = 2*acos(0); typedef long long ll; typedef complex<double> Complex; int nextInt() { int x; scanf("%d", &x); return x; } ll nextLL() { ll x; scanf("%lld", &x); return x; } //TEMPLATE //MAIN int main() { //freopen("in.txt", "r", stdin); int a = nextInt(), b = nextInt(); int c = a + b; char s[1000]; sprintf(s, "%d", c); vector<char> v; int j = 0; for (int i = strlen(s) - 1; i >= 0; i--) { v.push_back(s[i]); j++; if (j == 3 && s[i - 1] != '-' && i > 0) { v.push_back(','); j = 0; } } while (!v.empty()) { cout << v.back(); v.pop_back(); } cout << endl; }
相关文章推荐
- PAT A 1001. A+B Format (20)
- PAT A 1001. A+B Format (20)
- PAT A1001. A+B Format
- PAT A1001 A+B Format(20)
- PAT A1001. A+B Format
- 1001. A+B Format (20)
- 浙大PAT (Advanced Level) Practise 1001 A+B Format (20)
- 浙江大学PAT上机题解析之1001. A+B Format (20)
- PAT 甲级1001. A+B Format (20)
- PAT 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)(PAT)
- 1001. A+B Format (20)
- PAT甲级 1001. A+B Format
- 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- 2016/5/21 1001.Format the book list
- 1001. A+B Format (20)
- PAT(Advanced Level)1001. A+B Format (20)
- PAT1001. A+B Format