Advertisement
nontawat1996

1072

Sep 27th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int *stack2;
  5. int *stack;
  6. int main()
  7. {
  8.     char ch[5]= {'\0'};
  9.     int n,m,k,x,y,i,l,temp,start=0;
  10.     stack2=(int *)malloc(sizeof(int)*500000);
  11.     stack=(int *)malloc(sizeof(int)*500000);
  12.  
  13.     scanf("%d%d",&n,&m);
  14.     for(i=0; i<n; i++) scanf("%d",&stack[i]);
  15.     for(l=0; l<m; l++)
  16.     {
  17.         scanf("%s",ch);
  18.         //printf("--%s",ch);
  19.         if(ch[0]=='a')
  20.         {
  21.             scanf("%d%d",&x,&y);
  22.             x--;
  23.             y--;
  24.             temp=stack[x];
  25.             stack[x]=stack[y];
  26.             stack[y]=temp;
  27.         }
  28.         else if(ch[0]=='b')
  29.         {
  30.             scanf("%d%d",&x,&k);
  31.             x--;
  32.             stack[x]=k;
  33.         }
  34.         else if(ch[0]=='c')
  35.         {
  36.             start=0;
  37.             scanf("%d",&x);
  38.             x--;
  39.  
  40.             for(i=x; i>=0; i--)
  41.             {
  42.                 stack2[start]=stack[i];
  43.                 start++;
  44.             }
  45.             for(i=n-1; i>x; i--)
  46.             {
  47.                 stack2[start]=stack[i];
  48.                 start++;
  49.             }
  50.             for(i=0; i<n; i++) stack[i]=stack2[i];
  51.         }
  52.         else
  53.         {
  54.             scanf("%d",&x);
  55.             printf("%d\n",stack[x-1]);
  56.         }
  57.         memset(ch,'\0',5);
  58.     }
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement