# 高精度加法实现（c++）

0
11

```#include <iostream>
#include <cstdio>
using namespace std;
struct ListNode
{
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};

int main()
{
int  m,n;
cin>>m>>n;
int temp_m;
cin>>temp_m;
for(int i = 0;i<m-1;++i)
{
cin>>temp_m;
ListNode *new_m_node = new ListNode(temp_m);
index->next = new_m_node;
index = new_m_node;
}
int temp_n;
cin>>temp_n;
for(int i = 0;i<n-1;++i)
{
cin>>temp_n;
ListNode *new_n_node = new ListNode(temp_n);
index->next = new_n_node;
index = new_n_node;
}
while (ans->next!=NULL)
{
cout<<ans->val<<endl;
ans = ans->next;
}
cout<<ans->val;
return 0;
}

{
bool flag = true;
ListNode *ans = NULL;
while (l1!=NULL&&l2!=NULL)
{
{
if(flag)
{
flag = false;
ans = new ListNode((l1->val+l2->val)%10);
}
else
{
ans->next = new ListNode((l1->val+l2->val)%10);
ans = ans->next;
}
if((l1->val+l2->val)/10==1)
l1 = l1->next;
l2 = l2->next;
}
else
{
if(flag)
{
flag = false;
ans = new ListNode((l1->val+l2->val+1)%10);
}
else
{
ans->next = new ListNode((l1->val+l2->val+1)%10);
ans = ans->next;
}
if((l1->val+l2->val+1)/10==0)
l1 = l1->next;
l2 = l2->next;
}
}
if(l1==NULL&&l2==NULL)
{
{
ans->next = new ListNode(1);
}
else
{
}
}
if(l1==NULL&&l2!=NULL)
{
l1 = l2;
}
while (l1!=NULL)
{
{
if(flag)
{
flag = false;
ans =
}
else
{
ans->next = new ListNode((l1->val)%10);
ans = ans->next;
}

if((l1->val)/10==1)
l1 = l1->next;
}
else
{
if(flag)
{
flag = false;
ans = new ListNode((l1->val+1)%10);
}
else
{
ans->next = new ListNode((l1->val+1)%10);
ans = ans->next;
}

if((l1->val+1)/10==0)
l1 = l1->next;
}
}
{
ans->next = new ListNode(1);
}
else
{