PAT1001 A+B Format
思路:每三位分割,注意符号,首位不要出现逗号。
AC代码
#include <stdio.h>
#include <algorithm>
using namespace std;
void solve(int c) {
if(c < 0) printf("-");
c = abs(c);
int dig[20];
int len = 1;
do{
dig[len++] = c % 10;
c /= 10;
}while(c > 0);
for(int i = len-1; i > 0; i--) {
if(i%3 == 0 && i != len-1) printf(",");
printf("%d", dig[i]);
}
printf("\n");
}
int main() {
int a, b;
while(scanf("%d%d", &a, &b) != EOF) {
int c = a + b;
solve(c);
}
return 0;
}
如有不当之处欢迎指出!
PAT1001 A+B Format的更多相关文章
- 随笔2 PAT1001.A+B Format (20)
1001.A+B Format(20) 题目链接 1001.A+B Format (20) C++ 代码 第一次使用markdown,还不是很习惯,现在努力的在适应它 首先这道题我们很容易就可以读懂题 ...
- PAT----1001. A+B Format (20)解题过程
1001. A+B Format (20) github链接 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B Calculate a + b and output t ...
- PAT-1001 A+B Format (20 分) 注意零的特例
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...
- PAT---1001. A+B Format (20)
#include<stdio.h> int main(){ //定义要读入的两个整数 int a,b; //定义好放拆项用的数组 ]; //读入两个整数 scanf("%d%d& ...
- pat甲级题目1001 A+B Format详解
pat1001 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits ...
- Spring resource bundle多语言,单引号format异常
Spring resource bundle多语言,单引号format异常 前言 十一假期被通知出现大bug,然后发现是多语言翻译问题.法语中有很多单引号,单引号在format的时候出现无法匹配问题. ...
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- PAT甲级 1001. A+B Format (20)
题目原文: Calculate a + b and output the sum in standard format -- that is, the digits must be separated ...
- Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...
随机推荐
- sublime markdown编辑配色
Boxy package control : install package 选择Boxy theme preferences->settings配置: { "color_scheme ...
- 程序员之殇 —— (Are you afraid of me? Don't be.)灵感=神秘感
Are you afraid of me? (你们怕我吗?) Don't be.(不用怕) I am a programmer who just won't die.(我是不会死的程序员) 自从跟踪到 ...
- 深入浅出Hadoop之HDFS
hadoop生态系统一直是大数据灵域的热点,其中包括今天要聊的HDFS,和计划以后想聊的yarn, mapreduce, spark, hive, hbase, 已经聊过的zookeeper,等等. ...
- My Calendar III
class MyCalendarThree(object): """ Implement a MyCalendarThree class to store your ev ...
- git的学习笔记
1. Git介绍 Git是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. Git 最初是由Linus Torvalds设计开发的,用于管理Linux内核开发. Git ...
- JUnit5 技术前瞻
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6868495.html JUnit ...
- Installing VirtualBox
The (VirtualBox) website has a lot of quality documentation including: End-user documentation Techni ...
- Apache 配置SSI速记
1. 启用模块 httpd.conf LoadModule filter_module modules/mod_filter.so 2. <Directory 的Options配置中增加Incl ...
- linux 基础信息查询
Linux下如何查看版本信息 Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然. 1.# uname -a (Linux查看 ...
- HBase MetaStore和Compaction剖析
1.概述 客户端读写数据是先从HBase Master获取RegionServer的元数据信息,比如Region地址信息.在执行数据写操作时,HBase会先写MetaStore,为什么会写到MetaS ...