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 ... 这个错误是因为有两个相 ...
随机推荐
- 用MapViewOfFile处理大文件-内存不足
用MapViewOfFile处理大文件时,如果文件过大,如400M,则无法一次性映射入内存,否则会出现1132错误,即内存不足.原因可能为操作系统无法找到连续的内存.因此需要通过分页的方式,逐页将文件 ...
- test for python thread
#!/usr/bin/python # -*- coding: UTF-8 -*- import thread import time # 为线程定义一个函数 def print_time(threa ...
- IO (四)
1 深度遍历文件夹 示例: package java20; import java.io.File; import java.io.FilenameFilter; import java.text.S ...
- IO (一)
1 IO(Input Output)流概述 IO流用来处理设备之间的数据传输. java对数据的操作是通过流的方式. java用于操作流的对象都在IO包中. 流按操作数据分为两种:字节流和字符流. 流 ...
- python 调用 R,使用rpy2
python 与 R 是当今数据分析的两大主流语言.作为一个统计系的学生,我最早接触的是R,后来才接触的python.python是通用编程语言,科学计算.数据分析是其重要的组成部分,但并非全部:而R ...
- Object对象和function对象
Obejct对象 1.ECMAScript 中的 Object 对象与 Java 中的 java.lang.Object 相似. 2.ECMAScript中的所有对象都由Object对象继承而来,Ob ...
- ArcSDE 10.1安装、配置、连接
ArcSDE 10.1安装.配置.连接 (SQL Server 2008) 1 概述 ArcSDE 10.1的安装配置相较于ArcSDE 10.0和之前版本,有了一些显著的变化,比如取消了Post ...
- javascript:Json 和数组的遍历
首先看代码示例var json={a:1,b:2,c:3}; //json var array={1,2,3}; //数组 alert(json.a); //弹出1 或alert(json['a']) ...
- Could note find result map com.xxxx.entity.UserAccountDO
原因: insert语句的标签写错:应该是parameterType,而不应该是resultType
- 洛谷 [P3355] 骑士共存问题
二分图求最大独立点集 本问题在二分图中已处理过,此处用dinic写了一遍 #include <iostream> #include <cstdio> #include < ...