Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- ofstream g("date.out");
- int i,n,x,m;
- struct nod{
- int info;
- nod *next;
- };
- nod *p,*u;
- void adauga(nod *&p, nod *&u, int x){
- nod *q;
- q = new nod;
- q->info=x;
- q->next=NULL;
- if(p==0)
- p=u=q;
- else
- {
- u->next=q;
- u=q;
- }
- }
- void afisare(nod *p)
- {
- nod *q;
- for(q=p;q!=NULL;q=q->next)
- g<<q->info<<" ";
- g<<endl;
- }
- int main()
- {
- f>>n;
- for(i=1;i<=n;i++)
- {
- f>>x;
- adauga(p,u,x);
- }
- afisare(p);
- for(nod *q=p;q!=NULL;q=q->next)
- {
- nod *r=new nod;
- r->info=q->info;
- r->next=q->next;
- q->next=r;
- }
- afisare(p);
- for(nod *q=p;q->next!=NULL;)
- {
- if(q->next->info%3==0)
- {
- nod *r;
- r=q->next;
- q->next=q->next->next;
- if(r==u) u=q;
- delete r;
- }
- else q=q->next;
- }
- if(p->info%3==0)
- {
- nod *r=p;
- p=p->next;
- delete r;
- }
- afisare(p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement