# 超哥的小学期中考试

``````1
1
2222222222
8888888888
0
0``````

``````2
11111111110
``````

``````
#include <iostream>
#include <cstring>
#define MAX 100001
using namespace std;
class number
{
public:
friend istream &operator>>(istream &in,number &n)
{
in>>n.num;
return in;
}
friend ostream &operator<<(ostream &out,number &n)
{
return out;
}
friend bool flag_stop(number a,number b);
number operator +(number n);
private:
char num[MAX];
};
bool flag_stop(number a,number b)
{
if(a.num[0]=='0'&&b.num[0]=='0')return true;
else return false;
}
void reverse(char n[])
{
int len=strlen(n);
for(int i=len-1;2*i>len-1;i--)
{
swap(n[i],n[len-1-i]);
}
}
void num_add(char n1[],char n2[],char result[])
{
reverse(n1);
reverse(n2);
int i;
int len1=strlen(n1);
int len2=strlen(n2);
int min=len1<=len2?len1:len2;
int max=len1>len2?len1:len2;
for(i=0;i<min;i++)
{
result[i]=n1[i]+n2[i]-'0';
}
for(i=min;i<max;i++)
{
result[i]=len1>len2?n1[i]:n2[i];
}
for(i=0;i<max-1;i++)
{
result[i]-='0';
if(result[i]>9)
{
result[i+1]+=result[i]/10;
result[i]%=10;
}
result[i]+='0';
}
int k=max-1;
int last=result[max-1]-'0';
while(last)
{
result[k++]=last%10+'0';
last/=10;
}
result[k]=0;
reverse(result);
cout<<result;
}
number number::operator+(number n)
{
number s;
return s;
}
int main()
{
number a,b;
while(cin>>a>>b)
{
if(flag_stop(a,b))break;
number c=a+b;
cout<<c<<endl;
}
return 0;
}
``````

``````
#include <iostream>
#include <cstring>
#define MAX 100001
using namespace std;
class number
{
public:
friend istream &operator>>(istream &in,number &n)
{
in>>n.num;
return in;
}
friend ostream &operator<<(ostream &out,number &n)
{
out<<n.num;
return out;
}
friend bool flag_stop(number a,number b);
number operator +(number n);
private:
char num[MAX];
};
bool flag_stop(number a,number b)
{
if(a.num[0]=='0'&&b.num[0]=='0')return true;
else return false;
}

#include<algorithm>
number number::operator+(number n)
{
number cnt;
memset(cnt.num,0,sizeof(cnt.num));
int len1 = strlen(num);
for(int i=0; i<len1; i++)
num[i]-='0';
int len2 = strlen(n.num);
for(int i=0; i<len2; i++)
n.num[i]-='0';
reverse(num,num+len1);
reverse(n.num,n.num+len2);
int len = max(len1,len2);
for(int i=0; i<len; i++)
{
cnt.num[i] += num[i]+n.num[i];
if(cnt.num[i]>=10)
{
if(i==len-1)len++;
cnt.num[i+1]+= (cnt.num[i])/10;
cnt.num[i]%=10;
}
}
for(int i=0; i<len; i++)
cnt.num[i]+='0';
reverse(cnt.num,cnt.num+len);
return cnt;
}

int main()
{
number a,b;
while(cin>>a>>b)
{
if(flag_stop(a,b))break;
number c=a+b;
cout<<c<<endl;
}
return 0;
}
``````