Advertisement
jakaria_hossain

lightoj - 1133 - Array Simulation

Aug 21st, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fast()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. typedef long long ll;
  5. int main()
  6. {
  7. fast();
  8. ll t;
  9. cin>>t;
  10. for(ll i=1;i<=t;i++)
  11. {
  12. ll n,q,k;
  13. cin>>n>>q;
  14. ll ara[n+1];
  15. char x;
  16. for(ll j=0;j<n;j++)cin>>ara[j];
  17. while(q--)
  18. {
  19. cin>>x;
  20. if(x=='S')
  21. {
  22. cin>>k;
  23. for(ll j=0;j<n;j++)ara[j]+=k;
  24. }
  25. else if(x=='M')
  26. {
  27. cin>>k;
  28. for(ll j=0;j<n;j++)ara[j]*=k;
  29. }
  30. else if(x=='D')
  31. {
  32. cin>>k;
  33. for(ll j=0;j<n;j++)ara[j]/=k;
  34. }
  35. else if(x=='P')
  36. {
  37. cin>>k;
  38. ll w;
  39. cin>>w;
  40. ll z;
  41. z=ara[k];
  42. ara[k]=ara[w];
  43. ara[w]=z;
  44. }
  45. else
  46. {
  47. reverse(ara,ara+n);
  48. }
  49. }
  50. cout<< "Case "<<i<<":"<<endl;
  51. for(ll j=0;j<n-1;j++)cout<<ara[j]<< " ";
  52. cout<<ara[n-1]<<endl;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement