Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. void parseDot(char s[100], int &first, int &second) {
  7. int length = strlen(s);
  8. int temp = 0, dotFound = 0, negative = 1;
  9. for (int i = 0; i < length; i++) {
  10. if (s[i] == '.') {
  11. first = temp;
  12. dotFound = 1;
  13. temp = 0;
  14. continue;
  15. }
  16. if (s[i] == '-') {
  17. negative = -1;
  18. continue;
  19. }
  20. temp = temp * 10 + (s[i] - '0');
  21. }
  22.  
  23. second = -1;
  24. if (dotFound) {
  25. second = temp;
  26. } else {
  27. first = temp * negative;
  28. }
  29. }
  30.  
  31. int main(void) {
  32. int t;
  33. cin >> t;
  34. int start, end, p_id, c_id, s_id, r_id, slot;
  35. char query;
  36. char s[100];
  37.  
  38. // For any product (optionally )
  39. int stateSales[104][10000];
  40.  
  41. int productSales[104][60];
  42.  
  43. for (int i = 0; i < 104; i++) {
  44. for (int j = 0; j < 10000; j++)
  45. stateSales[i][j] = 0;
  46. for (int j = 0; j < 60; j++) {
  47. productSales[i][j] = 0;
  48. }
  49. }
  50. while (t--) {
  51. cin >> s;
  52. query = s[0];
  53. cin >> s;
  54. parseDot(s, start, end);
  55. cin >> s;
  56. parseDot(s, p_id, c_id);
  57. cin >> s;
  58. parseDot(s, s_id, r_id);
  59. //cout << query << " " << start << " " << end << " " << p_id << " " << c_id << " " << s_id << " " << r_id << endl;
  60.  
  61. if (query == 'S') {
  62.  
  63. // total sale on this day
  64. productSales[start][0] += 1;
  65.  
  66. // For this specific product
  67. productSales[start][(p_id - 1) * 5 + 1] += 1;
  68.  
  69. // For this specific product in this category
  70. if (c_id != -1) {
  71. productSales[start][(p_id-1) * 5 + 1 + c_id] += 1;
  72. }
  73.  
  74. // For any sale that happened in this state
  75. stateSales[start][(s_id-1) * 26] += 1;
  76.  
  77. // For any sale that happened in this state in this region
  78. if (r_id != -1)
  79. stateSales[start][(s_id-1) * 26 + r_id] += 1;
  80.  
  81. // For any sale that happened in that state for this particular product
  82. stateSales[start][(p_id-1) * 910 + (s_id-1) * 26 + 182] += 1;
  83.  
  84. // For any sale that happened in that state for this particular product
  85. // in this category
  86. if (c_id != -1)
  87. stateSales[start][(p_id - 1) * 910 + c_id * 182 + (s_id-1) * 26 + 182] += 1;
  88.  
  89. // For sale that happened in that state for this particular product
  90. // in this particular region
  91. if (r_id != -1) {
  92. stateSales[start][(p_id-1) * 910 + (s_id-1) * 26 + r_id + 182] += 1;
  93. }
  94. // For sale that happened in that state for this particular product
  95. // in this particular region in this category
  96.  
  97. if (r_id != -1 and c_id != - 1) {
  98. stateSales[start][(p_id-1) * 910 + c_id * 182 + (s_id-1) * 26 + r_id + 182] += 1;
  99. }
  100.  
  101. } else {
  102. int ans = 0;
  103. if (end == -1)
  104. end = start;
  105.  
  106. for (int i = start; i <= end; i++) {
  107. if (p_id == -1 and s_id == -1) {
  108. // all sales
  109. ans += productSales[i][0];
  110. } else if (s_id == -1 and p_id != -1 and c_id == -1) {
  111. // all sales of this product
  112. ans += productSales[i][(p_id-1) * 5 + 1];
  113. } else if (s_id == -1 and p_id != -1 and c_id != -1) {
  114. ans += productSales[i][(p_id-1) * 5 + c_id + 1];
  115. } else if (p_id == -1 and s_id != - 1 and r_id == -1) {
  116. // all sales in this state
  117. ans += stateSales[i][(s_id - 1) * 26];
  118. } else if (p_id == -1 and s_id != - 1 and r_id != -1) {
  119. // all sales in this state in this regin
  120. ans += stateSales[i][(s_id - 1) * 26 + r_id];
  121. } else if (p_id != -1 and c_id == -1 and s_id != -1 and r_id == -1) {
  122. ans += stateSales[i][(p_id-1) * 910 + (s_id-1) * 26 + 182];
  123. } else if (p_id != -1 and c_id == -1 and s_id != -1 and r_id != -1) {
  124. ans += stateSales[i][(p_id-1) * 910 + (s_id-1) * 26 + r_id + 182];
  125. } else if (p_id != -1 and c_id != -1 and s_id != -1 and r_id == -1) {
  126. ans += stateSales[i][(p_id - 1) * 910 + c_id * 182 + (s_id-1) * 26 + 182];
  127. } else
  128. ans += stateSales[i][(p_id-1) * 910 + c_id * 182 + (s_id-1) * 26 + r_id + 182];
  129.  
  130. }
  131.  
  132. cout << ans << endl;
  133.  
  134. }
  135.  
  136.  
  137. }
  138.  
  139. return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement