PAT A1001 A+B Format (20 分)
AC代码
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 11;
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
long long a, b;
scanf("%lld %lld", &a, &b);
long long sum = a + b;
int ans[maxn];
int num = 0;
if(sum < 0) {
printf("-");
sum = -sum;
}
do {
ans[num++] = sum % 10;
sum /= 10;
} while(sum != 0);
//reverse(ans, ans+num);2
// for(int i = num - 1; i >= 0; i--) printf("%d", ans[i]);
for(int i = num - 1, t = 1; i >= 0; i--,t++) {
printf("%d", ans[i]);
if(i > 0 && i % 3 == 0) {
printf(",");
}
t++;
}
return 0;
}
PAT A1001 A+B Format (20 分)的更多相关文章
- PAT 1001 A+B Format (20分) to_string()
题目 Calculate a+b and output the sum in standard format -- that is, the digits must be separated into ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- PAT乙级:1088 三人行 (20分)
PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...
- PAT乙级:1064 朋友数 (20分)
PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- [PAT] 1140 Look-and-say Sequence(20 分)
1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...
- pat 1132 Cut Integer(20 分)
1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...
- pat 1100 Mars Numbers(20 分)
1100 Mars Numbers(20 分) People on Mars count their numbers with base 13: Zero on Earth is called &qu ...
- pat 1108 Finding Average(20 分)
1108 Finding Average(20 分) The basic task is simple: given N real numbers, you are supposed to calcu ...
随机推荐
- 还是畅通工程(HDU 1233)
某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可 ...
- element-ui练习使用总结
<el-row> <el-col class="borderRed" :span="24"> <div class="g ...
- 利用Python构建时间序列模型解决实际问题的正确姿势
要本着应用到实际工作中目的去学时间序列分析,才能深入浅出的学会,不要纠结于理论,只听我的,我有信心说明白. 本章内容 趋势分析 序列分解 序列预测 序列分解 统计学基础铺垫 划分 时间序列按照季节性划 ...
- 在windows使用gvim的感受
用新下载的gvim写几行代码习惯一下,感觉vim用起来要比atom占用的内存少多了,更加的便捷.由于之前一直在用sublime text2,虽然我也很喜欢ST,但我还是抱着膜拜的心态来试了试gvim, ...
- php unicode转字符串
<?php /** * @param string $str 需转换字符,这里为单个字符 * @return string */ function get_unicode($str) { $bi ...
- 8. 使用Zuul构建微服务网关
使用Zuul构建微服务网关 8.1. 为什么要使用微服务网关 8.2. Zuul简介 8.3. 编写Zuul微服务网关 8.4. Zuul的路由端点 8.5. Zuul ...
- 2965 -- The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27893 ...
- pytorch-LeNet网络
LeNet网络的结构 输入的32x32x1的单通道图片, 第一层网络: 3x3x1x6的卷积层,步长为1, padding = 1, 经过2x2的池化操作 第二层网络: 5x5x6x16的卷积层, 步 ...
- ios-tableViewcell展开与收缩动画处理
[前言] 在使用华尔街见闻 app 时,看到它的 tableVeiw 上的 cell 具有很好的展开与收缩功能.于是自己想了一下实现,感觉应该挺简单的,于是心痒痒写个 demo 实现一波.华尔街见闻 ...
- 注解方式实现AOP编程
步骤: 1) 先引入aop相关jar文件 (aspectj aop优秀组件) spring-aop-3.2.5.RELEASE.jar [spring3.2源码] aopal ...