Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. /*
  2.  
  3. 以區域區分,所以先將區域丟進去
  4.  
  5. 檢查從頭到當前位址(k)的區域有沒有重複名字的
  6.  
  7. 如果沒有:
  8. 將當前輸入區域存入
  9. 將k往後一格
  10. 如果有:
  11. 跳過break
  12.  
  13. 最後將判斷有無的flag初始化 -> END
  14.  
  15. -------------------------------------
  16.  
  17. 接著是種類,把種類丟進所有區域(從0到k)
  18.  
  19. 檢查該區域是否有重複該型別
  20.  
  21. 如果沒有:
  22. 將種類存入該區域的種類
  23. 將amount存入amountstr[r][j];
  24. 將j往後一格
  25. 如果有:
  26. 將amount存入amountstr[r][i];
  27. 跳出break;
  28.  
  29. 將flag初始化
  30.  
  31. 全部存完後進到下個區域 並且將j重置
  32.  
  33.  
  34. */
  35.  
  36.  
  37. #include <iostream>
  38. #include <string>
  39. using namespace std;
  40.  
  41. int main()
  42. {
  43. int n,i,amount,k = 0,r,flag=0,q,temp;
  44.  
  45. string type,place;
  46.  
  47. cin >> n;
  48.  
  49. string typestr[n][n],placestr[n];
  50.  
  51. int amountstr[n][n],j;
  52.  
  53.  
  54. for (i = 0 ; i < n ; i++)
  55. {
  56. cin >> type >> amount >> place;
  57.  
  58. //區域運算區
  59.  
  60. for (r = 0 ; r <= k ; r++)
  61. {
  62. if (placestr[r] == place)
  63. {
  64. flag = 1;
  65. }
  66. }
  67. if ( flag == 0)
  68. {
  69. placestr[k] = place;
  70. k++;
  71. }
  72. //cout << "flag = " << flag <<endl << "k = " << k << endl;
  73. flag = 0;
  74. //r是區域
  75.  
  76. //種類運算區
  77.  
  78.  
  79. for (r = 0 ; r <= k ; r++)
  80. {
  81. for (q = temp ; q <= j ; q++)//種類新增運算
  82. {
  83. if (typestr[r][q] == type)
  84. {
  85. flag = 1;
  86. amountstr[r][q] += amount;
  87. break;
  88. }
  89. }
  90. if (flag == 0)
  91. {
  92. typestr[r][j] = type;
  93. amountstr[r][j] += amount;
  94. j++;
  95. }
  96. flag = 0;
  97.  
  98. }
  99.  
  100. }
  101.  
  102. for (r = 0 ; r < k ; r++)
  103. {
  104. cout << placestr[r] << ": ";
  105.  
  106. for (q = 0 ; q <= j ; q++)
  107. {
  108. cout << typestr[r][q] << "" << amountstr[r][q] <<",";
  109. }
  110. cout << endl;
  111.  
  112. }
  113.  
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement