当前位置:网站首页>Pat class A - A + B format
Pat class A - A + B format
2022-07-24 17:04:00 【Soldier Xiaobai】
A + B Format
Calculation a+b And output the sum in standard format ---- in other words , Add a comma every three digits from the lowest order ( Thousand separator ), If the result is less than four digits, there is no need to add .
Input format
All in one line , Contains two integers a and b.
Output format
All in one line , Output in standard format a+b And .
Data range
−106≤a,b≤106−106≤a,b≤106
sample input :
-1000000 9
sample output :
-999,991
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int c = a + b;
string num = to_string(c);
string res;
for(int i = num.size() - 1, j = 0; i >= 0; i --)
{
res = num[i] + res;
j ++;
if(j % 3 == 0 && i && num[i - 1] != '-') res = ',' + res;
}
cout << res << endl;
return 0;
}
边栏推荐
- AI opportunities for operators: expand new tracks with large models
- Envi grid resampling
- 荣耀CEO赵明:单一厂商很难实现全场景产品覆盖
- AXI协议(2):AXI架构的五个通道和两种事务
- At & T pseudo instruction and interpretation of CFI CFA
- Still shocked by the explosion in the movie? Then you must not miss this explosive plug-in of unity
- Kernel development
- AXI协议(1):AMBA总线介绍,AXI概念与背景介绍,AXI协议特点与功能
- 剑指 Offer 22. 链表中倒数第k个节点
- CPU comparison
猜你喜欢

Development dynamics | stonedb 2022 release milestone

Custom types: Enumeration

Live review | wonderful playback of Apache pulsar meetup (including PPT download)

Using unity to do simulation, I don't allow this chart plug-in, you don't know

Jupyter uses tips

Comparison of array and object merging methods assign, merge, defaults, defaultsdeep in lodash

一个实际使用SwiftUI 4.0中ViewThatFits自适应视图的例子

安全:如何为行人提供更多保护
[redis] -1. two ways of setting up environment based on docker

Still shocked by the explosion in the movie? Then you must not miss this explosive plug-in of unity
随机推荐
Topic 6 - message queue for client communication
Still developing games with unity? Then you're out. Try unity to build an answer system
JS to implement a promise of promises/a+ specification
Concept of IP, classification of IP, IP multiplexing technology
Small end format and big end format (little endian & big endian)
Axi protocol (3): handshake mechanism and implementation details of Axi architecture
709. Convert to lowercase letters
快速入门
Axi protocol (1): introduction to AMBA bus, introduction to Axi concept and background, characteristics and functions of Axi protocol
Axi protocol (2): five channels and two transactions of Axi architecture
What are the safe securities companies? I want to buy stocks on my mobile phone
Mysql增删改查、检索与约束(详细教学)
QT embed Notepad under win10
Meeting OA project progress (II)
EF LINQ Miscellany
查数据库实际数据增长情况
Programming language exercises (I)
Bring 120W goods in 15 seconds. You can also shoot such a popular video
What exactly is API?
1024 happy holidays