Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct str{
- int x;
- str *next, *pred;
- };
- int main()
- {
- str *beg, *last, * help;
- int h,E,cnt1(0),cnt2(0);
- cin>>E;
- beg=new str ;
- last=beg;
- while (cin>>h)
- {
- if (h==E)
- cnt1++;
- help=new str;
- help->x=h;
- last->next=help;
- help->pred=last;
- last=help;
- }
- last->next=NULL;
- help = beg->next;
- if (cnt1 >= 2){
- for (help=beg->next;help;help=help->next)
- {
- if (help ->x == E){
- cnt2++;
- }
- if (cnt2 == cnt1){
- help=help->pred;
- while (cnt2!=1){
- if (help->pred->x == E)
- cnt2--;
- cout<<help->x<<' ';
- help=help->pred;
- }
- return 0;
- }
- }
- }
- }
- /**
- 22
- 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
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement