(甲)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 ...
随机推荐
- jQuery--捕获键盘敲击
功能 当页面加载完成后,用户键盘按下某个键后,jQuery能够捕获到一个数字,从而执行一系列动作. 格式 1 2 3 4 5 6 7 8 9 10 11 12 $(function(){ $ ...
- 怎么快速了解自己的MySQL服务器
1.查看数据库服务器状态:status Linux 下的MySQL服务器状态 该列表中主要包括MySQL的版本(为version 5.1.61).运行平台(debian-linux-gnu(i68 ...
- Node.js下基于Express + Socket.io 搭建一个基本的在线聊天室
一.聊天室简单介绍 采用nodeJS设计,基于express框架,使用WebSocket编程之 socket.io机制.聊天室增加了 注册登录模块 ,并将用户个人信息和聊天记录存入数据库. 数据库采用 ...
- javascript运算符的优先级
最基木的运算符优先级就是所谓的“先乘除,后加减”.对于优先顺序处于同一层次上的运算符,按照从左到右出现的顺序计算.下面给出javascript定义的所有运算符的优先级.运算符 优先顺序成员选择.括号. ...
- 几种web字体格式
目前,文字信息仍是网站最主要的内容,随着CSS3技术的不断成熟,Web字体逐渐成为话题,这项让未来Web更加丰富多彩的技术拥有多种实现方案,其中之一是通过@font-face属性在网页中嵌入自定义字体 ...
- [CLR via C#]16. 数组
数组是允许将多个数据项当作一个集合来处理的机制.CLR支持一维数组.多维数组和交错数据(即由数组构成的数组).所有数组类型都隐式地从System.Array抽象类派生,后者又派生自System.Obj ...
- 数据库一次性插入10w条数据,怎么插入效率快
在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题 下面介绍SQL Server支持的两种批量 ...
- flask环境开发搭建
http://blog.csdn.net/chen_jint/article/details/50550636 ========== 因为笔者开发环境是win7pro,那么就以win7pro为例. p ...
- Visual Studio中设置默认VC++路径
菜单"View" -> "Other Windows" -> "Property Manager" 选择对应的配置并修改即可.
- mysql备份方法
在用PHP或者其他web脚本语言构架的应用系统中,数据库大部分是mysql其中就牵扯到了一个数据库日常备份导出等问题,大概有以下几种情况: 1.如果应用用的是开源的产品,如dz.pw和其他cms等一般 ...