Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream f("date.in");
  5. ofstream g("date.out");
  6.  
  7. int i,n,x,m;
  8. struct nod{
  9. int info;
  10. nod *next;
  11. };
  12.  
  13. nod *p,*u;
  14.  
  15. void adauga(nod *&p, nod *&u, int x){
  16. nod *q;
  17. q = new nod;
  18. q->info=x;
  19. q->next=NULL;
  20. if(p==0)
  21. p=u=q;
  22. else
  23. {
  24. u->next=q;
  25. u=q;
  26. }
  27. }
  28.  
  29. void afisare(nod *p)
  30. {
  31. nod *q;
  32. for(q=p;q!=NULL;q=q->next)
  33. g<<q->info<<" ";
  34. g<<endl;
  35. }
  36.  
  37. int main()
  38. {
  39. f>>n;
  40. for(i=1;i<=n;i++)
  41. {
  42. f>>x;
  43. adauga(p,u,x);
  44. }
  45. afisare(p);
  46. for(nod *q=p;q!=NULL;q=q->next)
  47. {
  48. nod *r=new nod;
  49. r->info=q->info;
  50. r->next=q->next;
  51. q->next=r;
  52. }
  53. afisare(p);
  54. for(nod *q=p;q->next!=NULL;)
  55. {
  56. if(q->next->info%3==0)
  57. {
  58. nod *r;
  59. r=q->next;
  60. q->next=q->next->next;
  61. if(r==u) u=q;
  62. delete r;
  63. }
  64. else q=q->next;
  65. }
  66. if(p->info%3==0)
  67. {
  68. nod *r=p;
  69. p=p->next;
  70. delete r;
  71. }
  72. afisare(p);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement