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 ...
随机推荐
- 基于PaaS和SaaS研发平台体系
基于PaaS和SaaS研发的商业云平台实战 背景介绍 SaaS.PaaS.IaaS等云服务模式已经被大家普遍认可,在研发过程中借力一些PaaS和SaaS平台,能够提升产品的研发速度和功能稳定程度.本文 ...
- random(随机模块)
程序中有很多地方需要用到随机字符,比如登录网站的随机验证码,通过random模块可以很容易生成随机字符串 >>> random.randrange(1,10) #返回1-10之间的一 ...
- 【maven】maven源码打包
1.打包时附加外部Jar包 <!--编译+外部 Jar打包--> <plugin> <artifactId>maven-co ...
- 【vue】遇到的问题
[一]项目编译的时候报错 npm install npm WARN @mtfe/thrift@2.3.7 requires a peer of thrift@0.11.0 but none is in ...
- POJ2480 Longge's problem
题意 Language:Default Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1064 ...
- 开机或者安装系统时提示tsc: Fast TSC calibration failed解决方法
其实这个问题很简单,主要是时间不对的问题. 就拿我遇到这个问题来说.我是在vm虚拟机中安装了xenserver,然后在物理机安装xencenter连接xenserver,然后在安装新的虚拟机时遇到这个 ...
- Scala方法定义,方法和函数的区别,将方法转换成函数
1. 定义方法和函数 1.1. 定义方法 方法的返回值类型可以不写,编译器可以自动推断出来,但是对于递归函数,必须指定返回类型 1.2. 定义函数 1.3.方法和函数的区别 在函数式编程语言中,函数是 ...
- 07机器学习实战k-means
K-Means原理初探 K-Means算法的思想很简单,对于给定的样本集,按照样本之间的距离大小,将样本集划分为K个簇.让簇内的点尽量紧密的连在一起,而让簇间的距离尽量的大. 如果我们想直接求上式的最 ...
- windows下能搭建php-fpm吗 phpstudy
这个Windows和Linux系统是不一样的,因为一般nginx搭配php需要php-fpm中间件,但是Windows下需要第三方编译. 下载的包里有php-cgi.exe 但不是php-fpm如果想 ...
- Maven 环境隔离实践
现在将SpringMVC中Maven环境隔离实践总结如下: 1. 在pom中配置 <resources> <resource> <directory>src/mai ...