list实现大整数加法
2024-09-12 19:39:59
#include<iostream>
#include<list>
#include<string>
using namespace std; list<int> BigAddList(list<int> La,list<int> Lb )
{
list<int> Lc;
list<int> ::iterator it1,it2;
it1=La.begin();
it2=Lb.begin(); int carry=;
while(it1!=La.end()||it2!=Lb.end())
{
int c=carry;
if(it1!=La.end())
{
c=c+(*it1);
it1++;
}
if(it2!=Lb.end())
{
c=c+(*it2);
it2++;
}
carry=c/;
Lc.push_back(c%);
}
if(carry>) Lc.push_back(carry);
return Lc;
} int main()
{
int i,T;
cin>>T;
for(int j=;j<T;j++)
{
string s,t;
cin>>s>>t;
list<int>La,Lb,Lc; for(i=;i<s.size();i++)
{
La.push_front(s[i]-''); }
for(i=;i<t.size();i++)
Lb.push_front(t[i]-''); Lc=BigAddList(La,Lb);
Lc.reverse(); for(list<int>::iterator it=Lc.begin();it!=Lc.end();it++)
{
cout<<*it; }
cout<<endl;
}
}
最新文章
- 再谈JavaScript闭包及应用
- cocos2dx 3.x(移动修改精灵坐标MoveTo与MoveBy)
- 菜鸟教程之工具使用(十)——用BlazeMeter录制JMeter测试脚本
- ReentrantLock
- 【python】Python 3 +pycharm中文支持解决方案
- apache开源项目--kafka
- (图文教程)帝国cms7.0列表页模板调用多说评论次数
- # Consumed parameters
- Pandas 错误笔记(持续更新)
- 面向对象(__str__和__repr__方法)
- Android OpenSL ES 开发:OpenSL ES利用SoundTouch实现PCM音频的变速和变调
- IO流的种类
- iOS - 跳转到系统设置
- Div里超出部分,省略号显示
- python第四十四课——继承性之单继承
- 语义化的HTML及其目的
- STM32 硬件UART接收超时检测设置
- JavaScript四种数值取整方法
- 20.Add Two Numbers(两个链表的和)
- Mybatis详解