#include<iostream>
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
struct shu{
int x[13000];
int len;
bool zheng;
shu(){
memset(x,0,sizeof(int)*10005);
len=0;
zheng=true;
}
bool iszero();
int judge (shu& b);
};
bool shu::iszero(){
for (int i=0;i<len;++i){
if (x[i]!=0){
return false;
}
}
return true;
}
int judge (shu &a ,shu& b) {
if (a.len>b.len){
return 1;
}
else if (a.len<b.len){
return -1;
}
else if (a.len==b.len){
for (int i=a.len;i>=0;--i){
if (a.x[i]>b.x[i]){
return 1;
}
else if (a.x[i]<b.x[i]){
return -1;
}
}
return 0;
}
}
//chuli
void s(char* a,shu &a1){
int l=strlen(a);
if (a[0]=='-'){
a1.zheng=false;
a1.len=l-1;
for (int i=l-1, j=0;i>=1;--i,++j){
a1.x[j]=(a[i]-'0');
}
}
else{
for (int i=l-1,j=0;i>=0;--i,++j){
a1.x[j]=(a[i]-'0');
}
a1.len=l;
}
}
void Add (shu& a,shu& b,shu& c){
if (a.iszero()&&b.iszero()){
return ;
}
if (a.zheng==false&&b.zheng==true){
swap(a,b);
}
if (a.zheng&&b.zheng){
for (int i=0;i<(a.len>b.len?a.len:b.len);++i){
c.x[i]+=(a.x[i]+b.x[i]);
if (c.x[i]>=10){
c.x[i]%=10;
c.x[i+1]++;
}
}
c.zheng=true;
c.len=(a.len>b.len?a.len:b.len);
}
else if (a.zheng==true&&b.zheng==false){
if (judge(a,b)==0){
return ;
}
else if (judge(a,b)==1){
//cout<<"here";
for (int i=0;i<a.len;++i){
c.x[i]+=(a.x[i]-b.x[i]);
if (c.x[i]<0){
int j=i+1;
while (a.x[j]==0){++j;}
c.x[j]--;
for (int k=i+1;k<j;++k)
c.x[k]+=9;
c.x[i]+=10;
}
}
c.zheng=true;
}
else if (judge(a,b)==-1){
// cout<<"here";
for (int i=0;i<b.len;++i){
c.x[i]+=(b.x[i]-a.x[i]);
if (c.x[i]<0){
int j=i+1;
while (b.x[j]==0){++j;}
c.x[j]--;
for (int k=i+1;k<j;++k)
c.x[k]+=9;
c.x[i]+=10;
}
}
c.zheng=false;
}
}
else if (!a.zheng&&!b.zheng){
for (int i=0;i<(a.len>b.len?a.len:b.len);++i){
c.x[i]+=(a.x[i]+b.x[i]);
if (c.x[i]>=10){
c.x[i]%=10;
c.x[i+1]++;
}
}
c.zheng=false;
}
c.len=(a.len>b.len?a.len:b.len)+1;
}
int main()
{
char a[13000],b[13000];
struct shu a1,b1,c1;
scanf("%s %s",a,b);
s(a,a1);s(b,b1);
Add(a1,b1,c1);
bool m=true;
bool v=true;
if (c1.iszero()){
cout<<'0';return 0;
}
if (!c1.zheng){
cout<<'-';
}
for (int i=c1.len;i>=0;--i){
if (c1.x[i]!=0){
m=false;
if(c1.x[i]<0)
cout<<-c1.x[i];
else{
cout<<c1.x[i];
}
}
}
return 0;
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
struct shu{
int x[13000];
int len;
bool zheng;
shu(){
memset(x,0,sizeof(int)*10005);
len=0;
zheng=true;
}
bool iszero();
int judge (shu& b);
};
bool shu::iszero(){
for (int i=0;i<len;++i){
if (x[i]!=0){
return false;
}
}
return true;
}
int judge (shu &a ,shu& b) {
if (a.len>b.len){
return 1;
}
else if (a.len<b.len){
return -1;
}
else if (a.len==b.len){
for (int i=a.len;i>=0;--i){
if (a.x[i]>b.x[i]){
return 1;
}
else if (a.x[i]<b.x[i]){
return -1;
}
}
return 0;
}
}
//chuli
void s(char* a,shu &a1){
int l=strlen(a);
if (a[0]=='-'){
a1.zheng=false;
a1.len=l-1;
for (int i=l-1, j=0;i>=1;--i,++j){
a1.x[j]=(a[i]-'0');
}
}
else{
for (int i=l-1,j=0;i>=0;--i,++j){
a1.x[j]=(a[i]-'0');
}
a1.len=l;
}
}
void Add (shu& a,shu& b,shu& c){
if (a.iszero()&&b.iszero()){
return ;
}
if (a.zheng==false&&b.zheng==true){
swap(a,b);
}
if (a.zheng&&b.zheng){
for (int i=0;i<(a.len>b.len?a.len:b.len);++i){
c.x[i]+=(a.x[i]+b.x[i]);
if (c.x[i]>=10){
c.x[i]%=10;
c.x[i+1]++;
}
}
c.zheng=true;
c.len=(a.len>b.len?a.len:b.len);
}
else if (a.zheng==true&&b.zheng==false){
if (judge(a,b)==0){
return ;
}
else if (judge(a,b)==1){
//cout<<"here";
for (int i=0;i<a.len;++i){
c.x[i]+=(a.x[i]-b.x[i]);
if (c.x[i]<0){
int j=i+1;
while (a.x[j]==0){++j;}
c.x[j]--;
for (int k=i+1;k<j;++k)
c.x[k]+=9;
c.x[i]+=10;
}
}
c.zheng=true;
}
else if (judge(a,b)==-1){
// cout<<"here";
for (int i=0;i<b.len;++i){
c.x[i]+=(b.x[i]-a.x[i]);
if (c.x[i]<0){
int j=i+1;
while (b.x[j]==0){++j;}
c.x[j]--;
for (int k=i+1;k<j;++k)
c.x[k]+=9;
c.x[i]+=10;
}
}
c.zheng=false;
}
}
else if (!a.zheng&&!b.zheng){
for (int i=0;i<(a.len>b.len?a.len:b.len);++i){
c.x[i]+=(a.x[i]+b.x[i]);
if (c.x[i]>=10){
c.x[i]%=10;
c.x[i+1]++;
}
}
c.zheng=false;
}
c.len=(a.len>b.len?a.len:b.len)+1;
}
int main()
{
char a[13000],b[13000];
struct shu a1,b1,c1;
scanf("%s %s",a,b);
s(a,a1);s(b,b1);
Add(a1,b1,c1);
bool m=true;
bool v=true;
if (c1.iszero()){
cout<<'0';return 0;
}
if (!c1.zheng){
cout<<'-';
}
for (int i=c1.len;i>=0;--i){
if (c1.x[i]!=0){
m=false;
}
if (!m){if(c1.x[i]<0)
cout<<-c1.x[i];
else{
cout<<c1.x[i];
}
}
}
return 0;
}
真的是一边哭一边写的 自己太弱了
以后的目标是天下!!