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进 ...
随机推荐
- tomcat安全加固
-R 640 conf/*3. 首次安装完成后立即删除webapps下面的所有代码rm -rf /srv/apache-tomcat/webapps/*4. 注释或删除 tomcat-users.xm ...
- 小游戏Item表
[Config]1|0|我|1|10|500|0|8|2|4|b5222d10-55a7-4789-8541-8e7430345d54|0|0[Config] [Config]2|1|公主|1|0|5 ...
- HDU 1513 最长子序列
Palindrome Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 百度前端技术学院2015JavaScript基础部分-BOM
5.1 任务描述 实现以下函数 // 判断是否为IE浏览器,返回-1或者版本号 function isIE() { // your implement } // 设置cookie function s ...
- 关于<form>标签
<form>用于为用户输入创建HTML表单,表单用于向服务器传输数据 form是块级元素,其前后会产生折行 <form>包含: 1.input元素:(根据不同的type属性,输 ...
- 关于mongodb的复合索引新功能
最新在做一个项目,由于查询字段较多,且查询较频繁,所以我做了一个复合索引,将所有需要查询的字段都做到索引里,做了一个名为s_1_m_1_c_1_v_1_year_1_month_1_week_1_da ...
- Fiddler-2 Fiddler抓包原理
1 fiddler抓包是在 客户端和服务器之间建立一个代理服务器,监听本机发出的请求和服务器返回的响应结果. 截一张官网的图: 2 启动fiddler之前,[dinghanhua]先来看一下代理服务器 ...
- 记AppStore 被打回的经历
在快驰已然有半年时间之久. 见证了“快货运”产品,在不断摧残的环境中成长着. 两个人,将一个产品亲手从无到有的构建,有过心酸.有过累和有过憔悴,但当“快货运”开始上APP store时,又让人觉得开 ...
- iOS推送生成服务器端p12文件
生成服务器端推送p12文件 所需文件:A.开发证书 aps_production.cer B.本地导出的私钥 : aps_production.p12 C.生成证书时用到的请求文件:Push.c ...
- 涵涵和爸爸习惯养成进度表(一)(May 5 - May 25)
规则说明 三周时间(21天)内,没有哭脸,不超过三个无表情脸,可以给一个奖励(动画书等) 涵涵违反规则,在爸爸和妈妈都同意的情况下,可以给无表情脸 爸爸违反规则,在妈妈和涵涵都同意的情况下,可以给无表 ...