Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 以區域區分,所以先將區域丟進去
- 檢查從頭到當前位址(k)的區域有沒有重複名字的
- 如果沒有:
- 將當前輸入區域存入
- 將k往後一格
- 如果有:
- 跳過break
- 最後將判斷有無的flag初始化 -> END
- -------------------------------------
- 接著是種類,把種類丟進所有區域(從0到k)
- 檢查該區域是否有重複該型別
- 如果沒有:
- 將種類存入該區域的種類
- 將amount存入amountstr[r][j];
- 將j往後一格
- 如果有:
- 將amount存入amountstr[r][i];
- 跳出break;
- 將flag初始化
- 全部存完後進到下個區域 並且將j重置
- */
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int n,i,amount,k = 0,r,flag=0,q,temp;
- string type,place;
- cin >> n;
- string typestr[n][n],placestr[n];
- int amountstr[n][n],j;
- for (i = 0 ; i < n ; i++)
- {
- cin >> type >> amount >> place;
- //區域運算區
- for (r = 0 ; r <= k ; r++)
- {
- if (placestr[r] == place)
- {
- flag = 1;
- }
- }
- if ( flag == 0)
- {
- placestr[k] = place;
- k++;
- }
- //cout << "flag = " << flag <<endl << "k = " << k << endl;
- flag = 0;
- //r是區域
- //種類運算區
- for (r = 0 ; r <= k ; r++)
- {
- for (q = temp ; q <= j ; q++)//種類新增運算
- {
- if (typestr[r][q] == type)
- {
- flag = 1;
- amountstr[r][q] += amount;
- break;
- }
- }
- if (flag == 0)
- {
- typestr[r][j] = type;
- amountstr[r][j] += amount;
- j++;
- }
- flag = 0;
- }
- }
- for (r = 0 ; r < k ; r++)
- {
- cout << placestr[r] << ": ";
- for (q = 0 ; q <= j ; q++)
- {
- cout << typestr[r][q] << "" << amountstr[r][q] <<",";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement