当前位置:网站首页>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;
}
边栏推荐
- ZCMU--5023: 家庭划分(C语言)
- Bring 120W goods in 15 seconds. You can also shoot such a popular video
- The differences of several deletions in SQL
- 2022年最新浙江建筑安全员模拟题库及答案
- Getting started with arcpy
- With notes: printing order of synchronous, asynchronous, micro task and macro task
- JS to implement a promise of promises/a+ specification
- regular expression
- JSP custom tag library -- select tag
- 【零基础】充分理解WebGL(八)
猜你喜欢

Mcd12q1 data shows multiple classifications in envi

Topic 6 - message queue for client communication

quick get start

JSP custom tag library --foreach

EF LINQ Miscellany

MODIS 16 day data monthly / quarterly synthesis

Bring 120W goods in 15 seconds. You can also shoot such a popular video

It's time to consider slimming down your app

DBF menu driver: librarydatabaseproject

Notebook computer purchase guide (specific brand and model are not recommended)
随机推荐
C font usage effect
804. Unique Morse code word
IP的概念,IP的分类,IP复用技术
Logisim group experiment 10 single cycle MIPS CPU
剑指 Offer 22. 链表中倒数第k个节点
1309. Decode letter to integer mapping
会议OA项目进度(一)
AI opportunities for operators: expand new tracks with large models
Rare earth Developer Conference | Apache pulsar committee Liu Dezhi shares the way of cloud native technology transformation
Axi protocol (3): handshake mechanism and implementation details of Axi architecture
Method of querying comma separated strings in a field by MySQL
PAT甲级——A + B 格式
剑指 Offer 25. 合并两个排序的链表
AXI协议(1):AMBA总线介绍,AXI概念与背景介绍,AXI协议特点与功能
为什么被调函数内部不能用 sizeof(arr) / size(arr[0]) 计算数组长度?
Qsqldatabase: solution of qmmysql driver not loaded
jvm类加载子系统
Custom types: Enumeration
QT QML virtual keyboard
Small end format and big end format (little endian & big endian)