Advertisement
Guest User

array simulation

a guest
Jan 26th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include<stdio.h>
  2. int main ()
  3. { int i,j,b,k,l,x,y,t,n,m,w,z; char a;
  4. scanf("%d",&t);
  5. for (i=0;i<t;i++){
  6. scanf(" %d %d ",&n, &m);
  7. int arr[n]; //the array :)
  8. for(j=0;j<n;j++){scanf("%d ",&arr[j]);}
  9. b=0;
  10. while(b<m){b++;
  11. scanf(" %c",&a);
  12. if(a=='S'){scanf(" %d",&x); for(k=0;k<n;k++)
  13. arr[k]=arr[k]+x;}
  14. else if(a=='M'){scanf(" %d",&x); for(k=0;k<n;k++)
  15. arr[k]=arr[k]*x;}
  16. else if(a=='D'){scanf(" %d",&x); for(k=0;k<n;k++)
  17. arr[k]=arr[k]/x;}
  18.  
  19. else if(a=='R'){int arrrev[n];
  20. for(k=0,l=n-1;k<n,l>=0;k++,l--){
  21. arrrev[k]=arr[l];}
  22. for(k=0;k<n;k++)
  23. arr[k]=arrrev[k];
  24. }
  25.  
  26. else if(a=='P'){scanf(" %d %d ",&z, &y);
  27. w=arr[z]; arr[z]=arr[y]; arr[y]=w;}
  28. }
  29.  
  30. printf("Case %d:\n",i+1);
  31. for(j=0;j<n;j++){
  32. printf("%d ",arr[j]);
  33. } }
  34.  
  35. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement