Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct str{
  7. int x;
  8. str *next, *pred;
  9. };
  10. int main()
  11. {
  12. str *beg, *last, * help;
  13. int h,E,cnt1(0),cnt2(0);
  14. cin>>E;
  15. beg=new str ;
  16. last=beg;
  17. while (cin>>h)
  18. {
  19. if (h==E)
  20. cnt1++;
  21. help=new str;
  22. help->x=h;
  23. last->next=help;
  24. help->pred=last;
  25. last=help;
  26. }
  27. last->next=NULL;
  28.  
  29. help = beg->next;
  30. if (cnt1 >= 2){
  31. for (help=beg->next;help;help=help->next)
  32. {
  33. if (help ->x == E){
  34. cnt2++;
  35. }
  36. if (cnt2 == cnt1){
  37. help=help->pred;
  38. while (cnt2!=1){
  39. if (help->pred->x == E)
  40. cnt2--;
  41. cout<<help->x<<' ';
  42. help=help->pred;
  43. }
  44. return 0;
  45. }
  46.  
  47. }
  48. }
  49.  
  50. }
  51.  
  52. /**
  53. 22
  54. 1 2 3 4 5 22 1 2 3 4 5 6 7 22 8 9 10 11 22 12 13 14 15 16 22 17 18
  55. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement