PAT (Advanced Level) Practise:1001. A+B Format
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input
-1000000 9
Sample Output
-999,991
题意分析:
输出(a+b)的结果,输出格式需要使用逗号把数值分割。
提交代码:
#include <stdio.h> int main(void)
{
int out[];
int i, len, tmp;
int a, b, c; scanf("%d %d", &a, &b); c = a + b;
if(c < )
{
printf("-");
c = -c;
} len = ;
do {
out[len] = c % ;
c /= ;
len++;
} while(c != ); for(i = ; i < len; i++)
{
printf("%d", out[len--i]);
tmp = len - i - ;
//if((len-i-1)%3 == 0 && (len-i) > 1)
if(tmp != && tmp % == )
printf(",");
} return ;
}
PAT (Advanced Level) Practise:1001. A+B Format的更多相关文章
- PAT (Advanced Level) Practise:1002. A+B for Polynomials
[题目链接] This time, you are supposed to find A+B where A and B are two polynomials. Input Each input f ...
- PAT (Advanced Level) Practise:1027. Colors in Mars
[题目链接] People in Mars represent the colors in their computers in a similar way as the Earth people. ...
- PAT (Advanced Level) Practise:1008. Elevator
[题目链接] The highest building in our city has only one elevator. A request list is made up with N posi ...
- PAT (Basic Level) Practise:1001. 害死人不偿命的(3n+1)猜想
[题目链接] 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在19 ...
- PAT (Basic Level) Practise:1040. 有几个PAT
[题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...
- PAT (Advanced Level) Practise 1001 解题报告
GiHub markdown PDF 问题描述 解题思路 代码 提交记录 问题描述 A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判 ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- PAT (Basic Level) Practise:1032. 挖掘机技术哪家强
[题目链接] 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行 ...
- PAT (Basic Level) Practise:1005. 继续(3n+1)猜想
[题目链接] 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进 ...
随机推荐
- MongoDB aggregate 运用篇 个人总结
最近一直在用mongodb,有时候会需要用到统计,在网上查了一些资料,最适合用的就是用aggregate,以下介绍一下自己运用的心得.. 别人写过的我就不过多描述了,大家一搜能搜索到N多一样的,我写一 ...
- SQL指定字段指定顺序排序
SELECT * FROM [ProjectInfo]ORDER BY (CASE DepartmentName WHEN 'AAA' THEN 1 WHEN 'BBB' THEN 2 WHEN 'C ...
- .NET截取指定长度汉字超出部分以"..."代替
/// <summary> /// 将指定字符串按指定长度进行剪切, /// </summary> /// <param name= "oldStr " ...
- oracle 递归应用(挺复杂的)
最近做数据过滤觉得很有必要记录下整个过程,说不定下次就不知道了. 废话不多说开始: 表结构: 企业表(自关联,采用树的形式记录分子公司) 区域表(自关联,采用树的形式记录省/市/县/乡,数据量大) 公 ...
- C# MD5加密
public static string Encrypt(string txt) { System.Security.Cryptography.MD5CryptoServiceProvider md5 ...
- 为bootstrap添加更多自定义图标
From: http://blog.csdn.net/mengxiangfeiyang/article/details/45224731 Twitter Bootstrap 真是前端开发的瑞士军刀,作 ...
- C++小项目:directx11图形程序(九):总结
整篇文章中对于directx11的知识的介绍并不多,我也不知道怎么介绍,也应该说对于directx,它有它自己的部分,比如设备(device),设备上下文(devicecontext),顶点缓存,索引 ...
- 在CDH5.5.0上安装Phoenix1.2
1.下载CLABS版本的Phoenix CLABS_PHOENIX-4.5.2-1.clabs_phoenix1.2.0.p0.774-el6.parcel和manifest.json文件 2.将文件 ...
- 查询java 类加载的路径
在Spring 3.x企业应用开发实战中看到一个能经常用到的jsp,记录下,查看类的加载路径, 在jar包冲突引起的奇葩问题时很好用.使用方法 srcAdd.jsp?className=java.ne ...
- Oracle 行转列(不固定行数的行转列,动态)(转)
http://bbs.csdn.net/topics/330039676 SQLSERVER :行列转换例子: http://www.cnblogs.com/gaizai/p/3753296.htm ...