我太SB了!!处理一次就可以了!!
#include<cstdio>
#include<cstring>
char s1[101],s2[101];
int f1[301],f2[301];
bool check(int *f)
{
for (int i=1;i<=300;i++)
if ((f[i]&&f[i-1])||f[i]>1) return false;
return true;
}
void deal()
{
for (int i=1;i<=301;i++)
{
if (f1[i]>=2)
{
if (i==1){f1[i+1]++;f1[i]=0;continue;}
else
{f1[i]-=2;f1[i+1]++;f1[i-2]++;}
continue;
}
else
{
if (f1[i]&&f1[i-1])
{
f1[i+1]++;f1[i]--;f1[i-1]--;
}
}
}
f1[1]+=f1[0];f1[0]=0;
}
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int i,j,k,l,n,m;
int t=0;
while (scanf("%s\n",s1)==1)
{
if (t) printf("\n");t++;
scanf("%s\n",s2);
int len1=strlen(s1);
int len2=strlen(s2);
if (s1[0]=='0'&&len1==1&&s2[0]=='0'&&len2==1){printf("0\n");continue;}
memset(f1,0,sizeof(f1));
for (i=len1;i>=1;i--)f1[len1-i+1]=s1[i-1]-'0';
for (i=len2;i>=1;i--)f1[len2-i+1]+=s2[i-1]-'0';
f1[0]=0;
while (check(f1)==false) deal();
for (i=301;i>=1;i--)if (f1[i])break;
for (;i>=1;i--) printf("%d",f1[i]); printf("\n");
}
return 0;
}
#include<cstdio>
#include<cstring>
char s1[101],s2[101];
int f1[301],f2[301];
bool check(int *f)
{
for (int i=1;i<=300;i++)
if ((f[i]&&f[i-1])||f[i]>1) return false;
return true;
}
void deal()
{
for (int i=1;i<=301;i++)
{
if (f1[i]>=2)
{
if (i==1){f1[i+1]++;f1[i]=0;continue;}
else
{f1[i]-=2;f1[i+1]++;f1[i-2]++;}
continue;
}
else
{
if (f1[i]&&f1[i-1])
{
f1[i+1]++;f1[i]--;f1[i-1]--;
}
}
}
f1[1]+=f1[0];f1[0]=0;
}
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int i,j,k,l,n,m;
int t=0;
while (scanf("%s\n",s1)==1)
{
if (t) printf("\n");t++;
scanf("%s\n",s2);
int len1=strlen(s1);
int len2=strlen(s2);
if (s1[0]=='0'&&len1==1&&s2[0]=='0'&&len2==1){printf("0\n");continue;}
memset(f1,0,sizeof(f1));
for (i=len1;i>=1;i--)f1[len1-i+1]=s1[i-1]-'0';
for (i=len2;i>=1;i--)f1[len2-i+1]+=s2[i-1]-'0';
f1[0]=0;
while (check(f1)==false) deal();
for (i=301;i>=1;i--)if (f1[i])break;
for (;i>=1;i--) printf("%d",f1[i]); printf("\n");
}
return 0;
}