nicuvlad76

1256

Mar 27th, 2021 (edited)
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 100001
  3. using namespace std;
  4. ifstream fin("date.in");
  5.  
  6. struct node
  7. {
  8.   char key;
  9.   node *next;
  10. };
  11. node*l;
  12.  
  13. void AddLast(node*&l, char x)
  14. {
  15.   node*q=new node;
  16.   q->key=x;
  17.   q->next=NULL;
  18.   if(l==NULL)l=q;
  19.   else
  20.   {
  21.     node*p;
  22.     for(p=l; p->next!=NULL; p=p->next);
  23.     p->next=q;
  24.   }
  25. }
  26.  
  27.  
  28. void AddFirst(node*&p, char x)
  29. {
  30.   node*q=new node;
  31.   q->key=x;
  32.   q->next=p;
  33.   p=q;
  34. }
  35. bool palindrom(node *l)
  36. {
  37.   node*l2=NULL,*q,*p;
  38.   for(q=l; q; q=q->next)
  39.     AddFirst(l2,q->key);
  40.  
  41.   for(p=l,q=l2; p!=NULL &&q!=NULL; p=p->next,q=q->next)
  42.     if(p->key!=q->key)return 0;
  43.   return 1;
  44. }
  45.  
  46. void Citire(node* &l)
  47. {
  48.   char x;
  49.   while(fin>>x)
  50.     AddLast(l,x);
  51. }
  52. int main()
  53. {
  54.  
  55.   Citire(l);
  56.   cout<<palindrom(l);
  57.   return 0;
  58. }
  59.  
Add Comment
Please, Sign In to add comment