Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int *stack2;
- int *stack;
- int main()
- {
- char ch[5]= {'\0'};
- int n,m,k,x,y,i,l,temp,start=0;
- stack2=(int *)malloc(sizeof(int)*500000);
- stack=(int *)malloc(sizeof(int)*500000);
- scanf("%d%d",&n,&m);
- for(i=0; i<n; i++) scanf("%d",&stack[i]);
- for(l=0; l<m; l++)
- {
- scanf("%s",ch);
- //printf("--%s",ch);
- if(ch[0]=='a')
- {
- scanf("%d%d",&x,&y);
- x--;
- y--;
- temp=stack[x];
- stack[x]=stack[y];
- stack[y]=temp;
- }
- else if(ch[0]=='b')
- {
- scanf("%d%d",&x,&k);
- x--;
- stack[x]=k;
- }
- else if(ch[0]=='c')
- {
- start=0;
- scanf("%d",&x);
- x--;
- for(i=x; i>=0; i--)
- {
- stack2[start]=stack[i];
- start++;
- }
- for(i=n-1; i>x; i--)
- {
- stack2[start]=stack[i];
- start++;
- }
- for(i=0; i<n; i++) stack[i]=stack2[i];
- }
- else
- {
- scanf("%d",&x);
- printf("%d\n",stack[x-1]);
- }
- memset(ch,'\0',5);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement