当前位置:网站首页>[summer daily question] Luogu p1601 a+b problem (high precision)
[summer daily question] Luogu p1601 a+b problem (high precision)
2022-07-29 07:28:00 【AC_ Dragon】
Topic link :P1601 A+B Problem( Hyperfine ) - Luogu | New ecology of computer science education (luogu.com.cn)
Title Description
High precision addition , amount to a+b problem, Don't worry about negative numbers .
Input format
Enter in two lines .a,b <= 10^500.
Output format
There is only one line of output , representative a+b Value .
Examples #1
The sample input #1
1
1Sample output #1
2Examples #2
The sample input #2
1001
9099Sample output #2
10100AC code:
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string f(string a,string b)
{
if(a=="0" && b=="0")
{
return "0";
}
int t1=a.size();
int t2=b.size();
int n=abs(t1-t2);
for(int i=0;i<n;i++)
{
if(t1>=t2)
b="0"+b;
else
a="0"+a;
}
string s; // and
int c=0; // carry
int d=0; // Low position
int len=a.size()-1;
for(int i=len;i>=0;i--)
{
d=(a[i]-'0'+b[i]-'0')%10+c;
if(d==10)
{
c=1;
s="0"+s;
continue;
}
s=to_string(d)+s;
c=(a[i]-'0'+b[i]-'0')/10;
if(c==1 && i==0)
s="1"+s;
}
if(s[0]=='0')
s="1"+s;
return s;
}
int main()
{
string a,b;
cin>>a>>b;
cout<<f(a,b);
return 0;
}边栏推荐
- cdc source能读完MySqlSnapshotSplit 就退出嘛
- PAT甲级 1146 拓扑顺序
- log4qt内存泄露问题,heob内存检测工具的使用
- Introduction and introduction of logback
- [summer daily question] Luogu p6336 [coci2007-2008 2] bijele
- [100 cases of unity practice] the single choice multiple choice judgment questions of unity universal question answering system are all common
- Leetcode buckle classic problem -- 4. Find the median of two positively ordered arrays
- Introduction to logback filter
- js中break与continue和return关键字
- Remote invocation of microservices
猜你喜欢

零数科技深度参与信通院隐私计算金融场景标准制定

Synchronous / asynchronous, blocking / non blocking and IO

halcon的安装以及在vs2017中测试,vs2017中dll的配置

关于大龄读博的几点回答?

SpingBoot整合Quartz框架实现动态定时任务(支持实时增删改查任务)

Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)

Operator3 - design an operator

How to establish EDI connection with Scania in Scania?

Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL

Prometheus与Grafana
随机推荐
7-2 计算正五边形的面积和周长 (25分)
H3C_ Using setting default static routing priority to realize the active and standby function of export dual lines
0 8 动态规划(Dynamic Programming)
用户列表 圆形头像并跟随小板块
5-整合swagger2
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
Paper reading (62):pointer networks
Practice of online problem feedback module (XVII): realize the online download function of excel template
Scala 高阶(九):Scala中的模式匹配
SEGGER 的硬件异常 分析
请问flink支持sqlServer数据库么?获取sqlServer数据库的变化
【暑期每日一题】洛谷 P7760 [COCI2016-2017#5] Tuna
写点dp
Introduction to logback appender
logback 中FileAppender具有什么功能呢?
[summer daily question] Luogu p6336 [coci2007-2008 2] bijele
How to use GS_ Expansion expansion node
Introduction to logback filter
QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
2-unified return class dto object