Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- using namespace std;
- struct stack{
- int inf;
- stack* next;
- };
- stack *init(){
- return NULL;
- }
- void push(stack *&h, int x){
- stack *top = new stack();
- top->inf = x;
- top->next = h;
- h = top;
- }
- int top(stack *&h){
- return h->inf;
- }
- int pop(stack *&h){
- int i = h->inf;
- stack *cur = h;
- h=h->next;
- delete cur;
- return i;
- }
- int main()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, k;//k is new element
- scanf("%d%d", &n, &k);
- stack *a = init();
- stack *res = init();
- int mn = 2000000001;
- for(int i = 0; i < n; i++){
- int cur; scanf("%d", &cur);
- push(a, cur);
- if(cur < mn) mn = cur;
- }
- while(a)
- {
- int cur = pop(a);
- push(res, cur);
- if(cur == mn) push(res, k);
- }
- while(res)
- printf("%d ", pop(res));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement