fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 7847 (C++) Sales Report
최초 업로드: 2025-08-20 22:07:51
최근 수정 시간: 2025-08-20 22:08:16
게시자: rlatjwls3333
카테고리: 백준
조회수: 5
# [Silver IV] Sales Report [문제 링크](https://www.acmicpc.net/problem/7847) ## 문제 설명 <p>The Unknown Trading Company have installed a new inventory-tracking system, which stores a complete database of goods and trading points worldwide. Each salespoint and each item was assigned an integer unique identifier (id). For every sale, the system logs id of the item, number of items sold, and id of the salespoint.</p> <p>Your task is to output a summary report, tabulating total sales by items and salespoints. The report must be a two-dimensional table, with the first row containing item ids in increasing order, first column containing salespoint ids in increasing order, and values inside the table representing total sales of corresponding item from the corresponding salespoint. The value in first column of the first row must be −1. The values in cells without corresponding sales must be 0.</p> ## 입력 <p>Input contains number of records <i>N</i>, followed by <i>N</i> triplets of integers <i>q<sub>i</sub></i> <i>s<sub>i</sub></i> <i>v<sub>i</sub></i>, where <i>q<sub>i</sub></i> -- item id, <i>s<sub>i</sub></i> -- salespoint id, <i>v<sub>i</sub></i> -- number of items sold.</p> ## 출력 <p>Output file must a table as described above, row-by-row.</p> ## 풀이 #### 가로줄이 고유키들, 세로줄이 판매 장소를 나타낼 때, 표의 값을 출력하라는 문제입니다. map<pair<int, int>, int>를 사용해 출력해 주었습니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; set<int> id, salespoint; map<pair<int, int>, int> total; while(n--) { int q, s, v; cin >> q >> s >> v; id.insert(q); salespoint.insert(s); total[{q, s}] += v; } cout << "-1 "; for(int q : id) cout << q << ' '; cout << '\n'; for(int s : salespoint) { cout << s; for(int q : id) cout << ' ' << total[{q, s}]; cout << '\n'; } } ```