fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin>>t;
  8. while(t--){
  9. vector<string>input;
  10. vector<int>vec;
  11. int var=0;
  12. map<string,float>ct;
  13. map<string,int>sm;
  14. map<string,int>s;
  15. while(true)
  16. {
  17. string s;
  18. cin>>s;
  19. if(s=="END")
  20. break;
  21. if(s=="CMD")
  22. vec.push_back(var);
  23. input.push_back(s);
  24. var++;
  25. }
  26.  
  27. for(int i=0;i<vec.size();i++)
  28. {int n=vec[i]+1;
  29. if(input[n]=="SM")
  30. { if(input[n+1]=="SET_COST")
  31. {
  32. if(input[n+2]=="SHOE")
  33. { float p=stof(input[n+3]);
  34. ct["SHOE"]=p;
  35. cout<<fixed<<setprecision(1)<<p<<endl;
  36. continue;
  37. }
  38. if(input[n+2]=="SHIRT")
  39. { float p=stof(input[n+3]);
  40. ct["SHIRT"]=p;
  41. cout<<fixed<<setprecision(1)<<p<<endl;
  42. continue;
  43. }
  44.  
  45.  
  46. }
  47.  
  48. if(input[n+1]=="ADD")
  49. {
  50. if(input[n+2]=="SHOE")
  51. { int p=stoi(input[n+3]);
  52. if(sm["SHOE"]==0){
  53.  
  54. sm["SHOE"]=p;
  55. cout<<p<<endl;
  56. }
  57. else
  58. cout<<-1<<endl;
  59. continue;
  60. }
  61. if(input[n+2]=="SHIRT")
  62. { int p=stoi(input[n+3]);
  63. if(sm["SHIRT"]==0){
  64. sm["SHIRT"]=p;
  65. cout<<p<<endl;
  66. }
  67. else
  68. cout<<-1<<endl;
  69. continue;
  70. }
  71. }
  72.  
  73. if(input[n+1]=="INCR")
  74. {
  75. if(input[n+2]=="SHOE")
  76. { int p=stoi(input[n+3]);
  77. if(sm["SHOE"]!=0)
  78. {
  79. sm["SHOE"]+=p;
  80. cout<<p<<endl;}
  81. else
  82. cout<<-1<<endl;
  83. continue;
  84. }
  85. if(input[n+2]=="SHIRT")
  86. { int p=stoi(input[n+3]);
  87. if(sm["SHOE"]!=0){
  88.  
  89. sm["SHIRT"]+=p;
  90. cout<<p<<endl;
  91. }else
  92. cout<<-1<<endl;
  93. continue;
  94. }
  95. }
  96. if(input[n+1]=="DCR")
  97. {
  98. if(input[n+2]=="SHOE")
  99. { int p=stoi(input[n+3]);
  100. if(sm["SHOE"]!=0){
  101.  
  102. sm["SHOE"]-=p;
  103. cout<<p<<endl;
  104. }
  105. else
  106. cout<<-1<<endl;
  107. continue;
  108. }
  109. if(input[n+2]=="SHIRT")
  110. { int p=stoi(input[n+3]);
  111. if(sm["SHIRT"]!=0){
  112.  
  113. sm["SHIRT"]-=p;
  114. cout<<p<<endl;
  115.  
  116. }
  117. else
  118. cout<<-1<<endl;
  119. continue;
  120. }
  121. }
  122.  
  123. if(input[n+1]=="GET_QTY")
  124. {
  125. if(input[n+2]=="SHOE")
  126. {
  127. cout<<sm["SHOE"]<<endl;
  128. continue;
  129. }
  130. if(input[n+2]=="SHIRT")
  131. {cout<<sm["SHIRT"]<<endl;
  132. continue;
  133. }
  134. }
  135.  
  136.  
  137. if(input[n+1]=="REMOVE")
  138. {
  139. if(input[n+2]=="SHOE")
  140. { sm["SHOE"]=0;
  141.  
  142. cout<<1<<endl;
  143. continue;
  144. }
  145. if(input[n+2]=="SHIRT")
  146. { sm["SHIRT"]=0;
  147. cout<<1<<endl;
  148. continue;
  149. }
  150. }
  151. } //sm is ended
  152. else if(input[n]=="S")
  153. {
  154. if(input[n+1]=="ADD")
  155. {
  156. if(input[n+2]=="SHOE")
  157. { int p=stoi(input[n+3]);
  158. if(s["SHOE"]==0){
  159.  
  160. s["SHOE"]=p;
  161. cout<<p<<endl;
  162. }
  163. else
  164. cout<<-1<<endl;
  165. continue;
  166. }
  167. if(input[n+2]=="SHIRT")
  168. { int p=stoi(input[n+3]);
  169. if(s["SHOE"]==0){
  170. s["SHIRT"]+=p;
  171. cout<<p<<endl;
  172. }
  173. else
  174. cout<<-1<<endl;
  175. continue;
  176. }
  177.  
  178. }
  179. if(input[n+1]=="INCR")
  180. {
  181. if(input[n+2]=="SHOE")
  182. { int p=stoi(input[n+3]);
  183. if(s["SHOE"]!=0){
  184.  
  185. s["SHOE"]+=p;
  186. cout<<p<<endl;
  187. }
  188. else
  189. cout<<-1<<endl;
  190. continue;
  191. }
  192. if(input[n+2]=="SHIRT")
  193. { int p=stoi(input[n+3]);
  194. if(s["SHIRT"]!=0)
  195. {
  196. s["SHIRT"]+=p;
  197. cout<<p<<endl;
  198. }
  199. else
  200. cout<<-1<<endl;
  201. continue;
  202. }
  203.  
  204. }
  205.  
  206. if(input[n+1]=="DCR")
  207. {
  208. if(input[n+2]=="SHOE")
  209. { int p=stoi(input[n+3]);
  210. if(s["SHOE"]!=0){
  211.  
  212. s["SHOE"]-=p;
  213. cout<<p<<endl;
  214. } else
  215. cout<<-1<<endl;
  216. continue;
  217. }
  218. if(input[n+2]=="SHIRT")
  219. { int p=stoi(input[n+3]);
  220. if(s["SHIRT"]!=0){
  221.  
  222. s["SHIRT"]-=p;
  223. cout<<p<<endl;
  224. } else
  225. cout<<-1<<endl;
  226. continue;
  227. }
  228.  
  229. }
  230.  
  231. if(input[n+1]=="GET_ORDER_AMOUNT")
  232. {
  233. float sum=s["SHOE"]*ct["SHOE"]+s["SHIRT"]*ct["SHIRT"];
  234. cout<<fixed<<setprecision(2)<<sum<<endl;
  235. continue;
  236. }
  237.  
  238. }
  239. //s ended
  240.  
  241. }
  242. }
  243. return 0;
  244. }
Success #stdin #stdout 0s 4340KB
stdin
1
CMD SM SET_COST SHOE 5
CMD SM SET_COST SHIRT 10
CMD SM ADD SHOE 5
CMD SM ADD SHIRT 10
CMD SM DCR SHIRT 5
CMD SM INCR SHOE 5
CMD SM GET_QTY SHIRT
CMD SM GET_QTY SHOE
CMD SM REMOVE SHIRT
CMD SM GET_QTY SHIRT
CMD S ADD SHOE 2
CMD S INCR SHOE 2
CMD S DCR SHOE 1
CMD S GET_ORDER_AMOUNT
END
stdout
5.0
10.0
5
10
5
5
5
10
1
0
2
2
1
15.00