Advertisement
selfpromise

dynamiclist №1 (2task)

Dec 15th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct element
  6. {
  7. int num;
  8. element *next;
  9. };
  10.  
  11. int main()
  12. {
  13. element *beg, *last, *help, *beg1, *last1, *help1;
  14. int n,m;
  15. cin>>n>>m;
  16. beg = new element;
  17. cin>>beg -> num;
  18. last=beg;
  19. for (int i=2; i<=n;i++){
  20. help = new element;
  21. cin>>help -> num;
  22. last -> next = help;
  23. last = help;
  24. }
  25. last -> next = NULL;
  26. beg1 = new element;
  27. cin>>beg1 -> num;
  28. last1=beg1;
  29. for (int i=2;i<=m;i++){
  30. help1 = new element;
  31. cin>>help1 -> num;
  32. last1 -> next = help1;
  33. last1 = help1;
  34. }
  35. last1 -> next = NULL;
  36. help = beg;
  37. help1 = beg1;
  38. bool f=1;
  39. while (help!=0 && help1!=0){
  40. if (help -> num != help1 -> num)
  41. {
  42. f=0;
  43. break;
  44. }
  45. help = help -> next;
  46. help1 = help1 -> next;
  47. }
  48. if (f==1)
  49. cout<<"YES";
  50. else
  51. cout<<"NO";
  52. return 0;
  53. }
  54. /**
  55. 4 4
  56. 1 2 3 4
  57. 1 2 3 4
  58. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement