PAT 甲级 1001 A+B Format (20)(20 分)
1001 A+B Format (20)(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
注意几个输出点:-991 991 1001 -1001
#include<iostream>
#include <sstream>
#include<string>
#include<stack>
#include<typeinfo> using namespace std; int main()
{
int a,b,flag=,temp=; cin>>a>>b; a+=b; if(a<)
{
flag=;
cout<<"-";
} stringstream ss;
ss<<a; string str=ss.str(); stack<char> s; for(int i=str.length()-;i>=flag;--i)
{
s.push(str[i]);
++temp; if(temp%== && i->=flag)
s.push(',');
} while(!s.empty())
{
cout<<s.top();
s.pop();
} cout<<endl; return ;
}
PAT 甲级 1001 A+B Format (20)(20 分)的更多相关文章
- PAT甲级 1001 A+B Format
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 1001 A+B Format ( ...
- PAT 甲级1001 A+B Format (20)(C++ -思路)
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...
- PAT甲级 1001. A+B Format (20)
题目原文: Calculate a + b and output the sum in standard format -- that is, the digits must be separated ...
- PAT甲级——1001 A+B Format (20分)
Calculate a+b and output the sum in standard format – that is, the digits must be separated into gro ...
- PAT 甲级 1001 A+B Format
https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 Calculate a + b and ou ...
- 1001 A+B Format (20 分)
1001 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits mu ...
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
随机推荐
- 错题:Test3
/** * * @ClassName: test3 * @Description: TODO(请问主程序运行结果是什么?) * @author yk * @date 2017年3月9日 上午11:20 ...
- loadrunner笔记---一
1.Loadrunner主要由Vugen,Controller和Analyais3部分组成 2.简述描述集合点和集合点函数 集合点可以同步虚拟用户,以便能在同一时刻执行任务,集合点函数lr_rende ...
- 20155208实验三 敏捷开发与XP实践
20155208实验三 敏捷开发与XP实践 一.实验内容 (1)在IDEA中使用工具(Code->Reformate Code)把下面代码重新格式化,再研究一下Code菜单,找出一项让自己感觉最 ...
- BZOJ 2002:Bounce 弹飞绵羊(分块)
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 14944 Solved: 7598 [Su ...
- PTA——类型转换
PTA习题 7-6 厘米换算英尺英寸 (15 分) #include<stdio.h> int main(){ int a; int b,c; scanf("%d",& ...
- (0)前端总结(HTML + CSS + JQ)
HTML 1.<meta charset="UTF-8"> #设置页面编码,这个设置英文则现在国内浏览器会弹出是否要转换中文 2.<title>我的第一个 ...
- lvm入门
实例: 使用lvm存储结构的主机需要扩容,现在我们已经将一个新的硬盘安装上去,将该新的硬盘的空间全部增加到主机上 20 ls /dev/sd* #查看新增加的硬盘名,我的为xvdb 21 ls /de ...
- software download
Develop Sourceinsight 3.50.0066 http://pan.baidu.com 这个版本支持输入文件名的一部分来查找文件,而不像3.50.0029必须输入完整的文件名 VFP ...
- java中的数据结构
1.链表的使用 使用时需要import java.util.List 和 java.util.ArrayList //返回list中的元素个数 int size(); //判断list中是否包含元素, ...
- MySQL Processlist--常见线程状态
常见SHOW PROCESSLIST返回结果中各种线程状态 ================================================ After createThis occu ...