#include<iostream>
using namespace std;
struct node
{
int data;
node*next;
};
class Add_8
{
public:
Add_8(){flag=0;}
void func();
void add(node *pf,node *qf);
private:
node*p;
node*q;
node*first;
int m,flag;
};
void Add_8::func()
{
node *s;
first=new node;
first->next=NULL;
while(cin>>m)
{
s=new node;
s->data=m;
s->next=first->next;
first->next=s;
}
while(first->next!=NULL)
{
cout<<first->next->data<<endl;
first->next=first->next->next;
}
//return first;
}
void Add_8::add(node *pf,node*qf)
{
node*temp;
p=pf->next;
q=qf->next;
while(p->next!=NULL&&q->next!=NULL)
{
p->data=(p->data+q->data+flag)%8;
flag=(p->data+q->data+flag)/8;
p=p->next;
q=q->next;
}
p->data=(p->data+q->data+flag)%8;
flag=(p->data+q->data+flag)/8;
if(q->next==NULL)
{
while(p->next!=NULL)
{
p=p->next;
p->data=(p->data+flag)%8;
flag=(p->data+flag)/8;
}
p->data=(p->data+flag)%8;
flag=(p->data+flag)/8;
if(flag>0)
{
temp=new node;
temp->next=NULL;
temp->data=flag;
p->next=temp;
}
}
if(p->next==NULL)
{
while(q->next!=NULL)
{
temp=new node;
temp->data=(q->data+flag)%8;
flag=(q->data+flag)/8;
p->next=temp;
temp->next=NULL;
}
if(flag>0)
{
temp=new node;
temp->next=NULL;
temp->data=flag;
p->next=temp;
}
}
p=first->next;
while(p->next!=NULL)
cout<<p->data;
cout<<p->next->data;
}
int main()
{
node *pf,*qf;
Add_8 obj1,obj2,obj3;
obj1.func();
cout<<"hello"<<endl;
obj2.func();
// if(pf==qf)
// cout<<"nima"<<endl;
cout<<qf->next->data<<endl;
//cout<<pf->next->data<<endl;
cout<<"hello"<<endl;
//obj3.add(pf,qf);
return 0;
}
using namespace std;
struct node
{
int data;
node*next;
};
class Add_8
{
public:
Add_8(){flag=0;}
void func();
void add(node *pf,node *qf);
private:
node*p;
node*q;
node*first;
int m,flag;
};
void Add_8::func()
{
node *s;
first=new node;
first->next=NULL;
while(cin>>m)
{
s=new node;
s->data=m;
s->next=first->next;
first->next=s;
}
while(first->next!=NULL)
{
cout<<first->next->data<<endl;
first->next=first->next->next;
}
//return first;
}
void Add_8::add(node *pf,node*qf)
{
node*temp;
p=pf->next;
q=qf->next;
while(p->next!=NULL&&q->next!=NULL)
{
p->data=(p->data+q->data+flag)%8;
flag=(p->data+q->data+flag)/8;
p=p->next;
q=q->next;
}
p->data=(p->data+q->data+flag)%8;
flag=(p->data+q->data+flag)/8;
if(q->next==NULL)
{
while(p->next!=NULL)
{
p=p->next;
p->data=(p->data+flag)%8;
flag=(p->data+flag)/8;
}
p->data=(p->data+flag)%8;
flag=(p->data+flag)/8;
if(flag>0)
{
temp=new node;
temp->next=NULL;
temp->data=flag;
p->next=temp;
}
}
if(p->next==NULL)
{
while(q->next!=NULL)
{
temp=new node;
temp->data=(q->data+flag)%8;
flag=(q->data+flag)/8;
p->next=temp;
temp->next=NULL;
}
if(flag>0)
{
temp=new node;
temp->next=NULL;
temp->data=flag;
p->next=temp;
}
}
p=first->next;
while(p->next!=NULL)
cout<<p->data;
cout<<p->next->data;
}
int main()
{
node *pf,*qf;
Add_8 obj1,obj2,obj3;
obj1.func();
cout<<"hello"<<endl;
obj2.func();
// if(pf==qf)
// cout<<"nima"<<endl;
cout<<qf->next->data<<endl;
//cout<<pf->next->data<<endl;
cout<<"hello"<<endl;
//obj3.add(pf,qf);
return 0;
}