原标题:一道PAT甲级编程题,你来挑战一下?
各位,今天给大家带来了一道PAT甲级试题,有些人可能对PAT不太了解,简单介绍一下,浙江大学计算机程序设计能力考试(Programming Ability Test,简称PAT)是由浙大组织的统一考试,号称IT界的托福。看下这个图:
这个考试有两项福利,一是考研浙大PAT甲级70以上免考机试,二是它联盟了很多企业,企业承诺优先录用PAT成绩优良的学生,并免除招聘时与考查程序设计能力相关的笔试环节,有兴趣和想法的可以尝试去报考一下。看一下有哪些企业:
好了,不多说了,上一道甲级中比较简单的题目:
A+B Format (20)
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并以标准格式输出总和 - 也就是说,数字必须用逗号分隔成三个组(除非少于四位数)。
每个输入文件都包含一个测试用例。每个案例包含一对整数a和b,其中-1000000 <= a,b <= 1000000。数字之间用空格分隔。
对于每个测试用例,您应该在一行中输出a和b的总和。总和必须以标准格式编写。
题目分析:
这道题关键在于用逗号隔开每三个数,要计算好逗号的位置。
if
(sum>=
1000000
){
printf
(
"%d,%03d,%03dn"
,sum/
1000000
, (sum/
1000
)%
1000
, sum%
1000
);
else
if
(sum >=
1000
){
printf
(
"%d,%03dn"
,sum/
1000
,sum%
1000
);
}
else
{
printf
(
"%dn"
, sum);
exit
(
0
);
return
0
;
怎么样各位,这是PAT甲级中比较简单的了,做题的前提是你得把英文原题题意理解清楚,你做上来了吗?
返回搜狐,查看更多
责任编辑:
声明:该文观点仅代表作者本人,搜狐号系信息发布平台,搜狐仅提供信息存储空间服务。