fork download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<malloc.h>
  4. using namespace std;
  5. typedef struct product_node
  6. {
  7. int p_id;
  8. int c_id;
  9. int s_id;
  10. int r_id;
  11. struct product_node* next;;
  12. }product_node;
  13. int numberOfDays;
  14. typedef struct day_information
  15. {
  16. int day;
  17. struct product_node *pro;
  18. int nodeCount;
  19. }day_information;
  20. day_information *day_info[105];
  21. day_information *getDayInformationNode(int d)
  22. {
  23. day_information *temp = (day_information*)malloc(sizeof(day_information));
  24. temp->day = d;
  25. temp->nodeCount = 0;
  26. temp->pro = NULL;
  27. return temp;
  28. }
  29. product_node *getProductNode(int p, int c, int s, int r)
  30. {
  31. product_node *temp = (product_node*)malloc(sizeof(product_node));
  32. temp->c_id = c;
  33. temp->p_id = p;
  34. temp->s_id = s;
  35. temp->r_id = r;
  36. temp->next = NULL;
  37. return temp;
  38.  
  39. }
  40. void init()
  41. {
  42. numberOfDays = 0;
  43. for (int i = 1; i <= 101; i++)
  44. {
  45. day_info[i] = getDayInformationNode(i);
  46.  
  47. }
  48. }
  49. void add_product_node(int sday, int c, int p, int s, int r)
  50. {
  51. numberOfDays++;
  52. product_node *temp = day_info[sday]->pro;
  53. if (temp == NULL)
  54. {
  55. day_info[sday]->pro = getProductNode(p, c, s, r);
  56.  
  57. }
  58. else
  59. {
  60. while (temp->next != NULL)
  61. {
  62. temp = temp->next;
  63. }
  64. temp->next = getProductNode(p, c, s, r);
  65. }
  66. day_info[sday]->nodeCount = day_info[sday]->nodeCount + 1;
  67.  
  68. }
  69.  
  70. int getResultDaywise(int startDay, int cid, int pid, int rid, int sid)
  71. {
  72. int countp = 0;
  73. product_node *temp = day_info[startDay]->pro;
  74. if (temp == NULL)
  75. return 0;
  76. if (pid > 0 && cid > 0 && rid > 0 && sid > 0)
  77. {
  78. while (temp)
  79. {
  80. if (temp->p_id == pid&&temp->c_id == cid&&temp->r_id == rid&&temp->s_id == sid)
  81. {
  82. countp++;
  83. }
  84. temp = temp->next;
  85. }
  86. return countp;
  87. }
  88. else if (pid > 0 && cid == 0 && sid > 0 && rid > 0)
  89. {
  90. while (temp)
  91. {
  92. if (temp->p_id == pid&&temp->r_id == rid&&temp->s_id == sid)
  93. {
  94. countp++;
  95. }
  96. temp = temp->next;
  97. }
  98. return countp;
  99. }
  100. else if (pid > 0 && cid == 0 && sid > 0 && rid == 0)
  101. {
  102. while (temp)
  103. {
  104. if (temp->p_id == pid&&temp->s_id == sid)
  105. {
  106. countp++;
  107. }
  108. temp = temp->next;
  109. }
  110. return countp;
  111. }
  112. else if (pid > 0 && cid > 0 && sid > 0 && rid == 0)
  113. {
  114. while (temp)
  115. {
  116. if (temp->p_id == pid&&temp->c_id == cid&&temp->s_id == sid)
  117. {
  118. countp++;
  119. }
  120. temp = temp->next;
  121. }
  122. return countp;
  123. }
  124. else if (pid == -1 && sid == -1)
  125. {
  126. return day_info[startDay]->nodeCount;
  127. }
  128. else if (pid == -1 && sid > 0 && rid > 0)
  129. {
  130. while (temp)
  131. {
  132. if (temp->r_id == rid&&temp->s_id == sid)
  133. {
  134. countp++;
  135. }
  136. temp = temp->next;
  137. }
  138. return countp;
  139. }
  140. else if (pid == -1 && sid > 0 && rid == 0)
  141. {
  142. while (temp)
  143. {
  144. if (temp->s_id == sid)
  145. {
  146. countp++;
  147. }
  148. temp = temp->next;
  149. }
  150. return countp;
  151. }
  152. else if (pid > 0 && cid > 0 && sid == -1)
  153. {
  154. while (temp)
  155. {
  156. if (temp->p_id == pid&&temp->c_id == cid)
  157. {
  158. countp++;
  159. }
  160. temp = temp->next;
  161. }
  162. return countp;
  163. }
  164. else if (pid > 0 && cid == 0 && sid == -1)
  165. {
  166. while (temp)
  167. {
  168. if (temp->p_id == pid)
  169. {
  170. countp++;
  171. }
  172. temp = temp->next;
  173. }
  174. return countp;
  175. }
  176.  
  177. }
  178. int getResult(int startDay, int endDay, int cid, int pid, int rid, int sid)
  179. {
  180. int countp = 0;
  181. if (endDay == 0)
  182. {
  183. return getResultDaywise(startDay, cid, pid, rid, sid);
  184.  
  185. }
  186. for (int i = startDay; i <= endDay; i++)
  187. {
  188. countp += (getResultDaywise(startDay, cid, pid, rid, sid));
  189. }
  190. return countp;
  191. }
  192. int main()
  193. {
  194. int tc;
  195. cin >> tc;
  196. init();
  197. while (tc--)
  198. {
  199. char c;
  200. int startDay = 0, endDay = 0, pid = 0, cid = 0, sid = 0, rid = 0;
  201. cin >> c;
  202. if (c == 'S')
  203. {
  204. char dot1, dot2;
  205. cin >> startDay >> pid >> dot1;
  206. if (dot1 == '.')
  207. {
  208. cout << ". hai\n";
  209. cin >> cid >> sid >> dot2;
  210. if (dot2 == '.')
  211. cin >> rid;
  212. }
  213. else
  214. {
  215. cout << ". nhi\n";
  216. cin >> sid >> dot2;
  217. if (dot2 == '.')
  218. cin >> rid;
  219. }
  220. printf("%d %d %d %d %d\n", startDay, cid, pid, sid, rid);
  221. add_product_node(startDay, cid, pid, sid, rid);
  222.  
  223. }
  224. else
  225. {
  226. char dot1, dot2, dot3;
  227. cin >> startDay >> dot1;
  228. if (dot1 == '.')
  229. {
  230. cin >> endDay >> pid >> dot2;
  231. if (dot2 == '.')
  232. {
  233. cin >> cid >> sid >> dot3;
  234. if (dot3 == '.')
  235. cin >> rid;
  236. }
  237. else
  238. {
  239. cin >> sid >> dot3;
  240. if (dot3 == '.')
  241. cin >> rid;
  242. }
  243. }
  244. else
  245. {
  246. cin >> pid >> dot2;
  247. if (dot2 == '.')
  248. {
  249. cin >> cid >> sid >> dot3;
  250. if (dot3 == '.')
  251. cin >> rid;
  252. }
  253. else
  254. {
  255. cin >> sid >> dot3;
  256. if (dot3 == '.')
  257. cin >> rid;
  258. }
  259.  
  260. }
  261. printf("%d %d %d %d %d %d\n", startDay, endDay, cid, pid, sid, rid);
  262. int res = getResult(startDay, endDay, cid, pid, rid, sid);
  263. cout << res << endl;
  264. }
  265.  
  266.  
  267. }
  268. return 0;
  269. }
Success #stdin #stdout 0s 15240KB
stdin
2
S 1 1.3 2.5
S 2 2 3.5
Q 2 2.3 3.5
S 1 1.2 3.4
Q 1 1 -1
S 3 2.3 6.7
S 3 2.4 6.8
S 2 2 7.8
Q 3 2 6.7
Q 3 2 6
Q 1.3 2 -1
stdout
. hai
1 3 1 2 5
. nhi
2 0 2 0 0