#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int too(string &s1){
s1='0'+s1;
int ans=0;
int i=s1.size()-1;
while(i>0){
if(s1[i]>'1'){
ans=1;
s1[i-1]++;
s1[i]-=2;
}
if(s1[i-1]>'1'){
ans=1;
s1[i-2]++;
s1[i]++;
s1[i-1]-=2;
}
for(i-=2;i>0;i--)
if(s1[i]>'1'){
ans=1;
s1[i-1]++;
s1[i]-=2;
s1[i+2]++;
break;
}
}
return ans;
}
void add(string &s1,string &s2){
if(s1.size()>=s2.size()){
for(int i=s2.size()-1,j=s1.size()-1;i>=0;i--,j--)
s1[j]+=s2[i]-'0';
s1='0'+s1;
}
else{
for(int i=s2.size()-1,j=s1.size()-1;j>=0;j--,i--)
s2[i]+=s1[j]-'0';
s1='0'+s2;
}
too(s1);
}
int reap(string &s){
// s2=string(s1.size(),'0');
s='0'+s;
int ans=0;
for(int i=s.size()-1;i>1;i--){
if(s[i]>'0'&&s[i-1]>'0'){
ans=1;
s[i-2]++;
s[i-1]--,s[i]--;
}
}
return ans;
}
int main(){
string s1,s2;
while(cin>>s1>>s2){
add(s1,s2);
int ans=1;
while(ans){
ans=reap(s1);
ans+=too(s1);
}
int i=0;
while(i<s1.size()-1&&s1[i]=='0')
i++;
while(i<s1.size())
cout<<s1[i++];
cout<<endl;
ws(cin);
if(!cin.eof())
cout<<endl;
}
}
#include <string>
#include <algorithm>
using namespace std;
int too(string &s1){
s1='0'+s1;
int ans=0;
int i=s1.size()-1;
while(i>0){
if(s1[i]>'1'){
ans=1;
s1[i-1]++;
s1[i]-=2;
}
if(s1[i-1]>'1'){
ans=1;
s1[i-2]++;
s1[i]++;
s1[i-1]-=2;
}
for(i-=2;i>0;i--)
if(s1[i]>'1'){
ans=1;
s1[i-1]++;
s1[i]-=2;
s1[i+2]++;
break;
}
}
return ans;
}
void add(string &s1,string &s2){
if(s1.size()>=s2.size()){
for(int i=s2.size()-1,j=s1.size()-1;i>=0;i--,j--)
s1[j]+=s2[i]-'0';
s1='0'+s1;
}
else{
for(int i=s2.size()-1,j=s1.size()-1;j>=0;j--,i--)
s2[i]+=s1[j]-'0';
s1='0'+s2;
}
too(s1);
}
int reap(string &s){
// s2=string(s1.size(),'0');
s='0'+s;
int ans=0;
for(int i=s.size()-1;i>1;i--){
if(s[i]>'0'&&s[i-1]>'0'){
ans=1;
s[i-2]++;
s[i-1]--,s[i]--;
}
}
return ans;
}
int main(){
string s1,s2;
while(cin>>s1>>s2){
add(s1,s2);
int ans=1;
while(ans){
ans=reap(s1);
ans+=too(s1);
}
int i=0;
while(i<s1.size()-1&&s1[i]=='0')
i++;
while(i<s1.size())
cout<<s1[i++];
cout<<endl;
ws(cin);
if(!cin.eof())
cout<<endl;
}
}
Comments
Post a Comment