Advertisement
Farjana_akter

Untitled

Apr 19th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. ll operation,top,ind,q[100000];
  5. map<ll,ll>word;
  6.  
  7.  
  8. void add(ll u)
  9. {
  10. ll flag=0;
  11. for(ll i=1; i<=ind; i++)
  12. {
  13. if(q[i]==u)
  14. {
  15. flag=1;
  16. break;
  17. }
  18. }
  19. if(flag==0)
  20. {
  21. q[++ind]=u;
  22. word[u]=0;
  23. cout<<"Operation #"<<operation++<<": success."<<endl;
  24. }
  25. else
  26. {
  27. cout<<"Operation #"<<operation++<<": same priority."<<endl;
  28. }
  29. }
  30.  
  31.  
  32. void close(ll u)
  33. {
  34. ll flag=0,index;
  35. if(top==u)
  36. {
  37. top=-1;
  38. }
  39. for(ll i=1; i<=ind; i++)
  40. {
  41. if(q[i]==u)
  42. {
  43. index=i;
  44. flag=1;
  45. break;
  46. }
  47. }
  48. if(flag==0)
  49. cout<<"Operation #"<<operation++<<": invalid priority."<<endl;
  50. else
  51. {
  52. cout<<"Operation #"<<operation++<<": close "<<u <<" with "<<word[u]<<"."<<endl;
  53. for(ll j=index; j<ind; j++)
  54. q[j]=q[j+1];
  55. ind--;
  56. }
  57. }
  58.  
  59.  
  60. void chat(ll w)
  61. {
  62. if(top!=-1)
  63. {
  64. word[top]+=w;
  65. cout<<"Operation #"<<operation++<<": success."<<endl;
  66. }
  67. else
  68. {
  69. ll flag=0;
  70. if(ind!=0)
  71. {
  72. flag=1;
  73. }
  74. if(flag==1)
  75. {
  76. word[q[1]]+=w;
  77. cout<<"Operation #"<<operation++<<": success."<<endl;
  78. }
  79. else
  80. {
  81. cout<<"Operation #"<<operation++<<": empty."<<endl;
  82. }
  83. }
  84. }
  85.  
  86. void Rotate(ll u)
  87. {
  88. ll flag=0;
  89. if(u<1 || u>ind)
  90. {
  91. flag=1;
  92. }
  93. if(flag==0)
  94. {
  95. ll far=q[u];
  96. for(ll i=u; i>=1; i--)
  97. {
  98. q[i]=q[i-1];
  99. }
  100. q[1]=far;
  101. cout<<"Operation #"<<operation++<<": success."<<endl;
  102. }
  103. else
  104. {
  105. cout<<"Operation #"<<operation++<<": out of range."<<endl;
  106. }
  107. }
  108.  
  109.  
  110.  
  111. void prior()
  112. {
  113. ll mx=-1e9,flag=-1;
  114. for(ll i=1; i<=ind; i++)
  115. {
  116. if(q[i]>mx)
  117. {
  118. mx=q[i];
  119. flag=i;
  120. }
  121. }
  122. if(flag==-1)
  123. {
  124. cout<<"Operation #"<<operation++<<": empty."<<endl;
  125. }
  126. else
  127. {
  128. Rotate(flag);
  129. }
  130. }
  131.  
  132.  
  133. void choose(ll u)
  134. {
  135. ll flag=0,index;
  136. for(ll i=1; i<=ind; i++)
  137. {
  138. if(q[i]==u)
  139. {
  140. flag=1;
  141. index=i;
  142. break;
  143. }
  144. }
  145. if(flag==0)
  146. {
  147. cout<<"Operation #"<<operation++<<": invalid priority."<<endl;
  148. }
  149. else
  150. {
  151. Rotate(index);
  152. }
  153. }
  154.  
  155.  
  156. void Top(ll u)
  157. {
  158. ll flag=0;
  159. for(ll i=1; i<=ind; i++)
  160. {
  161. if(q[i]==u)
  162. {
  163. flag=1;
  164. break;
  165. }
  166. }
  167. if(flag==0)
  168. cout<<"Operation #"<<operation++<<": invalid priority."<<endl;
  169. else
  170. {
  171. top=u;
  172. cout<<"Operation #"<<operation++<<": success."<<endl;
  173. }
  174. }
  175.  
  176.  
  177. void untop()
  178. {
  179. if(top==-1)
  180. {
  181. cout<<"Operation #"<<operation++<<": no such person."<<endl;
  182. }
  183. else
  184. {
  185. top=-1;
  186. cout<<"Operation #"<<operation++<<": success."<<endl;
  187. }
  188. return;
  189. }
  190.  
  191. void bye()
  192. {
  193. if(top!=-1 && word[top])
  194. {
  195. cout<<"Bye "<<top<<": "<<word[top]<<endl;
  196. }
  197. for(ll i=1; i<=ind; i++)
  198. {
  199. if(q[i]!=top && word[q[i]])
  200. {
  201. cout<<"Bye "<<q[i]<<": "<<word[q[i]]<<endl;
  202. }
  203. }
  204. }
  205.  
  206.  
  207.  
  208. int main()
  209. {
  210. ll t,i,j,k,n,cas,a;
  211. cin>>t;
  212. while(t--)
  213. {
  214. cin>>n;
  215. ind=0,top=-1,operation=1;
  216. word.clear();
  217. while(n--)
  218. {
  219. string s;
  220. ll w,u,x,y,z;
  221. cin>>s;
  222. if(s=="Add")
  223. {
  224. cin>>u;
  225. add(u);
  226. }
  227. else if(s=="Close")
  228. {
  229. cin>>u;
  230. close(u);
  231. }
  232. else if(s=="Chat")
  233. {
  234. cin>>w;
  235. chat(w);
  236. }
  237. else if(s=="Rotate")
  238. {
  239. cin>>x;
  240. Rotate(x);
  241. }
  242. else if(s=="Prior")
  243. {
  244. prior();
  245. }
  246. else if(s=="Choose")
  247. {
  248. cin>>u;
  249. choose(u);
  250. }
  251. else if(s=="Top")
  252. {
  253. cin>>u;
  254. Top(u);
  255. }
  256. else if(s=="Untop")
  257. {
  258. untop();
  259. }
  260. }
  261. bye();
  262. }
  263. return 0;
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement