PAT A 1001 A+B Format
来源:互联网 发布:陈奕迅专辑 知乎 编辑:程序博客网 时间:2024/06/06 23:24
https://www.patest.cn/contests/pat-a-practise/1001
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//MAINint 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;}
0 0
- PAT 1001 A+B Format
- pat 1001 A+B Format
- PAT 1001 A+B Format
- PAT 1001 A+B Format
- PAT A 1001 A+B Format
- PAT(A-LEVEL) 1001 A+B Format
- PAT A A+B Format
- PAT Advanced Level 1001:A+B Format
- PAT 甲级 1001 A+B Format
- [PAT]1001 A+B Format (20)
- PAT-甲级-1001 A+B Format
- [PAT] 1001A+B Format (20)
- PAT 1001 A+B Format (20)
- PAT 1001. A+B Format
- 【PAT】1001. A+B Format
- PAT A1001. A+B Format
- PAT 1001.A+B Format
- pat 1001. A+B Format
- linux快速安装软件一步到位
- android中的动画(一)
- java多线程并发
- JDBC学习(2)jdbc的初实现
- HDU 3448 Bag Problem 暴力枚举,DFS(maybe)
- PAT A 1001 A+B Format
- 缓冲区和数组的输入输出问题
- CSS3 基础(015_媒体查询 - 示例)
- Kafka中Consumer类源码介绍
- 数据的类型
- 二叉树的基本操作
- display ospf peer的输出解释
- Android插件化:从入门到放弃
- GROUP BY,WHERE,HAVING之间的区别和用法