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进 ...
随机推荐
- 更改星级评分条 RatingBar 的样式
1.首先在布局中引用星级评分条: <RatingBar android:id="@+id/room_ratingbar" styl ...
- (c语言编程)出现错误:null undeclared identifier
原因:没有添加头文件#include <stdio.h> 添加完头文件后,错误消失
- 译:Boost Property Maps
传送门:Boost Graph Library 快速入门 原文:Boost Property Map 图的抽象数学性质与它们被用来解决具体问题之间的主要联系就是被附加在图的顶点和边上的属性(prope ...
- JQuery ajax 异步传一个数组到 .net后台
可能使用JQuery Ajax传值到后台一个字符串,或者序列化后的表单大家都使用过,但是某些项目,需要我们一次传值一个数组到后台,这个时候有什么好的办法呢? 1.JS将数组转换为一个字符串,然后传值到 ...
- Delphi编译的程序如何获取管理员权限
1.制作manifest文件 <?xml version="1.0" encoding="UTF-8" standalone="yes" ...
- 几种通过JDBC操作数据库的方法,以及返回数据的处理
1.SQL TO String :只返回一个查询结果 例如查询某条记录的总数 rs = stmt.executeQuery(replacedCommand); if (rs ! ...
- 悲惨记忆。。QImage之 pixel() && setPixel()参数不要给反了。。。
QImage repairImg(width, height, QImage::Format_Mono); ; row < height; row++) { // uchar* ucRow = ...
- C#和Java在重写上的区别
C# class A { public string Get1() { return "A1"; } public virtual string Get2() { return & ...
- Jenkins_Maven_Git 持续集成及自动化部署 GentOS版
1.安装JDK JDK下载: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 新 ...
- entity framework 新手入门篇(4)-entity framework扩展之 entityframework.extended
对于EF的操作,我们已经有了大概的了解了,但对于实战来说,似乎还欠缺着一些常用的功能,那就是批量的删除,更新数据. 承接上面的部分,我们有一个叫做House的数据库,其中包含house表和seller ...