当前位置:网站首页>[high precision] decimal integer addition
[high precision] decimal integer addition
2022-06-11 19:38:00 【MC happy bitter Xiao afraid】
subject :
Title Description
Calculation x Hexadecimal integer a+b Value ,( 0 <= a, b <= 10^100);
Input format
first line : An integer x( 2 <=x<=10 || x=16), Represents the two integer digits of the second line x Hexadecimal number .
The second line : Two separated by spaces x Hexadecimal integer a and b.
Output format
a line :a+b Value ( Output in original decimal )
Input and output sample Columns
sample input 1:
10
10 15
sample output 1:
25
sample input 2:
16
A B
sample output 2:
15
Ideas :
Change on the high-precision template :
What needs to be changed :
① When storing in reverse order, it needs to be converted to x Base number
② Calculation %10 and /10 Change to %x and /x
③ When saving the calculation results, you should convert them to x Base number
CODE:
#include <bits/stdc++.h>
using namespace std;
const int N = 10010 ;
int a[N] , b[N] , c[N] ;
string ans ;
string add(string as , string bs , int x)
{
ans.clear () ;
memset (a , 0 , sizeof (a)) ;
memset (b , 0 , sizeof (b)) ;
memset (c , 0 , sizeof (c)) ;
int alen = as.size () , blen = bs.size () , clen = max (alen , blen) + 1 ;
for (int i = 1; i <= alen; i++)
{
if (as[alen - i] >= '0' && as[alen - i] <= '9')
a[i] = as[alen - i] - '0' ;
else
a[i] = as[alen - i] - 'A' + 10 ;
}
for (int i = 1; i <= blen; i++)
{
if (bs[blen - i] >= '0' && bs[blen - i] <= '9')
b[i] = bs[blen - i] - '0' ;
else
b[i] = bs[blen - i] - 'A' + 10 ;
}
for (int i = 1; i < clen; i++)
{
c[i] += a[i] + b[i] ;
c[i + 1] = c[i] / x ;
c[i] %= x ;
}
while (c[clen] == 0 && clen > 1)
{
clen -- ;
}
for (int i = clen; i >= 1; i --)
{
if (c[i] >= 0 && c[i] <= 9)
ans += c[i] + '0' ;
else
ans += c[i] - 10 + 'A' ;
}
return ans ;
}
int main()
{
string a , b ;
int x ;
cin >> x >> a >> b ;
cout << add (a , b , x) ;
return 0;
}
AC 了
边栏推荐
- Specific methods for porting WinCC flexible 2008 project to botu WinCC
- Pstack and dmesg
- Flash ckeditor rich text compiler can upload and echo images of articles and solve the problem of path errors
- Template and requirements of curriculum design of reinforced concrete structure in autumn 21 of Dagong [standard answer]
- [laravel series 7.5] event system
- AHB2APB_bridge 设计
- [solution] codeforces round 798 (Div. 2)
- Review of software testing technology
- First acquaintance with enterprise platform
- vs2010链接sql2008数据库时无法打开
猜你喜欢

iMeta | 南科大夏雨组纳米孔测序揭示微生物可减轻高海拔冻土温室气体排放
![[signal denoising] speech adaptive denoising based on nonlinear filter with matlab code](/img/fd/07cee3c51ac44ca40f730dd487aa20.png)
[signal denoising] speech adaptive denoising based on nonlinear filter with matlab code

RTL仲裁器设计

Common - name of conference room

Chrome tips - browser web page setting coding, solving the problem of web page garbled code, obtaining the latest version of charset plug-in, UTF-8 coding setting

Pyqt5 tips - button vertical display method, QT designer sets button vertical display.
【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?
【求助】請問如何讓微信公眾號文章在外部瀏覽器中打開後還能顯示下方的精選留言?

Flutter--Button浅谈

Anaconda安装、Jupyter Notebook默认启动路径修改及Nbextensions插件安装
随机推荐
【Laravel系列7.5】事件系统
CMU 15-445 database course lesson 5 text version - buffer pool
YOLOv3 Pytorch代码及原理分析(二):网络结构和 Loss 计算
司空见惯 - 会议室名称
Pstack and dmesg
WinCC flexible 2008项目移植到博途WinCC的具体方法
AHB2Standard_handshake_bridge 设计
Software requirements engineering review
Activate function formulas, derivatives, image notes
Yolov3 pytoch code and principle analysis (II): network structure and loss calculation
Use Mysql to determine the day of the week
Zzulioj 2903: the power of warriors
Chrome tips - browser web page setting coding, solving the problem of web page garbled code, obtaining the latest version of charset plug-in, UTF-8 coding setting
On Workflow selection
AHB2APB_bridge 设计
Expandable type of system
On the selection and design of management subsystem of collection system
What started mongodb? What are the application scenarios?
3D建模有什么技巧吗?
Longest strictly increasing subsequence