(甲)PAT-1001
1001. 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
主要是题目的groups of three 的of 的用法让我有点迷糊,最后确认是一种属性关系,在题目的意思为3个一组。
代码为:
/* https://www.patest.cn/contests/pat-a-practise/1001 author: LY 2016.6.26 */ #include<iostream> #include<string> #include<algorithm> using namespace std; int main() { int a,b,c; string s; scanf("%d%d",&a,&b); c=a+b; ,l=; ; //符号判断 ) { flag=; c=abs(c); } )!=) { s[i]=(c%)+'; c=c/; i++; l++; ==) { s[i]=','; i++; } } s[i]= c+'; //对a+b的和进行拆分(每3个数一组) ; ) printf("%c",'-'); ;j--) { printf("%c",s[j]); } printf("\n"); ; }
(甲)PAT-1001的更多相关文章
- PAT 1001 A+B 解题报告
PAT 1001 A+B 代码链接:传送门 题目链接:传送门 题目简述: 给定两个值a,b: 范围-1000000 <= a, b <= 1000000: 按指定格式输出a+b的结果,例: ...
- PAT 1001 害死人不偿命的(3n+1)猜想 (15)(C++&JAVA&Python)
1001 害死人不偿命的(3n+1)猜想 (15)(15 分) 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反 ...
- PAT 1001. A+B Format 解题
GitHub PDF 1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, t ...
- PAT 1001 A+B Fotmat
源码 1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calcula ...
- PAT 1001 Format
problem 1001 A+B Format (20)(20 point(s)) Calculate a + b and output the sum in standard format -- t ...
- PAT——1001 害死人不偿命的(3n+1)猜想 (15)
对给定的任一不超过1000的正整数n,简单地数一下,需要多少步(砍几下)才能得到n=1? 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值. 输出格式:输出从n计算到1需要的步数. 输入样例 ...
- PAT 1001 害死人不偿命的(3n+1)猜想
1001 害死人不偿命的(3n+1)猜想 (15 分) 卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复 ...
- PAT 1001. 害死人不偿命的(3n+1)猜想 (15)
卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在1950年的世界 ...
- PAT 1001
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into ...
- pat 1001 A+B Format
题目链接:传送门 题目简述: 1. 给定两个整数值a,b: 2.范围-1000000 <= a, b <= 1000000: 3.按指定格式输出结果 例:-100000 9 输出: -99 ...
随机推荐
- IE11之F12 Developer Tools--调试器(Debugger)
使用调试器工具在代码运行时对其导航.设置监视点和断点,查看调用堆栈,以及提高编译/精简JavaScript的可读性. 调试器可以帮助你了解为何你的代码片段会出现未按照预期方式运行.未在预期时间运行及在 ...
- 11.22 点餐APP第一阶段总结
第一个冲刺结束了,任务也算是完成了. 团队合作不像单独做那样想怎么来就怎么来,各个人都不同的意见,最后方案的需要每个人一致同意通过才能执行. 不过团队合作分配到每个人的任务也相对轻一点,而且遇到问题解 ...
- javaScript一些函数包括调试方法(二)
Number():设法把括号里面的值,转换成一个数,转换不了为数字的话,就返回NaN. 注意:Number()函数,会拒绝任何包含,非数字字符的字符串(阿拉伯数字.一个有效的小数位.+.-符号是允许的 ...
- for循环的嵌套,for循环的穷举迭代
for循环的嵌套 输入一个正整数,求阶乘的和 嵌套 Console.Write("请输入一个正整数:"); int ...
- C#的注释和快速开启工具的命令
1.注释的方法 1)sqlserver中,单行注释:—— 多行注释:/****/ 2)C#中,单行注释:// 多行注释:/****/ 3)C#中多行注释的快捷方式:启用ctrl+E+C ,撤 ...
- csharp:VerifyCode in winform or webform
winform: using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...
- 机器学习实战 - 读书笔记(13) - 利用PCA来简化数据
前言 最近在看Peter Harrington写的"机器学习实战",这是我的学习心得,这次是第13章 - 利用PCA来简化数据. 这里介绍,机器学习中的降维技术,可简化样品数据. ...
- 那一夜,我们..奋笔疾书敲出的--->>库存管理系统
说了会再见,最近好吗?无论你在哪里>也许你在温暖的家,或许你在身在异乡的城市;或许你高高的峰顶放生高歌,或许你还在陡峭的山峰半空努力攀爬.......相信我们都会登上顶峰,"会当凌绝顶 ...
- hdu 2952 Counting Sheep
本题来自:http://acm.hdu.edu.cn/showproblem.php?pid=2952 题意:上下左右4个方向为一群.搜索有几群羊 #include <stdio.h> # ...
- 说反话(c++实现)
描述:给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有 ...