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 ... 这个错误是因为有两个相 ...
随机推荐
- Python 字符串大小写操作
#coding=utf-8 #python中字符串的操作 # 字符串的大小写 s='hello_wOrld_oF_you' upper_str = s.upper() print('全部大写: ',u ...
- 获取用户IP地址的三个属性的区别 (HTTP_X_FORWARDED_FOR,HTTP_VIA,REMOTE_ADDR)
一.没有使用代理服务 器的情况: REMOTE_ADDR = 您的 IPHTTP_VIA = 没数值或不显示HTTP_X_FORWARDED_FOR = 没数值或不显示 二.使用透明代理服务器的情 况 ...
- Linux 下 编译Xerces-c++
按照 doc/html 文件夹中的详细指导编译 Xerces-C++ 共享库. 下面的命令展示了如何用压缩的源文件编译 Xerces-C++ 库. 这里假定在像 /home/ 这样的目录中有 xerc ...
- ORACLE 博客文章目录(2015
从接触ORACLE到深入学习,已有好几年了,虽然写的博客不多,质量也参差不齐,但是,它却是成长的历程的点点滴滴的一个见证,见证了我在这条路上的寻寻觅觅,朝圣的心路历程,现在将ORACLE方面的博客整理 ...
- 微信开发获取media_id错误码汇总
微信开发遇到的错误汇总: 1. 错误代码40001 "errcode": 40001, "errmsg": "invalid credentia ...
- 【转】Awk 命令学习总结、AWk命令系列学习(linux shell)
前面的话 学习linux 的同人,都知道linux shell文本处理能力非常强大.有一组强大的文本处理工具:grep,sed,awk . 其中grep 经常用作查找匹配文本.sed用作文本编辑替换. ...
- FastDFS角色配置参数思维导图
- IDEA精髓快捷键
删除一行:Ctrl+X 快速查找:Ctrl+F 打开文件目录结构: Ctrl+F12 可以把代码包在一个块内:Ctrl+Alt+T 替换文本:Ctrl+R, Alt+Shift+Up/Down,上/下 ...
- C++复制、压缩文件夹
之前写过一篇用zlib库来压缩的,但zlib只能压缩文件,我需要压缩文件夹,要想压缩文件夹还得利用zlib库自己写代码,我是真的服了,一个开源库这么不好用. C++复制文件夹也是麻烦事,网上这篇文章: ...
- MonogoDB 查询小结
MonogoDB是一种NoSQL数据库 优点: 1.数据的存储以json的文档进行存储(面向文档存储) 2.聚合框架查询速度快 3.高效存储二进制大对象 缺点: 1.不支持事务 2.文件存储空间占用过 ...