Array – Official House

1.2k 词

题目描述

You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room.
For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that v persons left.
Assume that initially no person lives in the building.

输入

In the first line, the number of notices n is given. In the following n lines, a set of four integers b, f, r and v which represents ith notice is given in a line.

输出

For each building, print the information of 1st, 2nd and 3rd floor in this order. For each floor information, print the number of tenants of 1st, 2nd, … and 10th room in this order. Print a single space character before the number of tenants. Print “####################” (20 ‘#’) between buildings.

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
int B[4][3][10];
int main() {
int n,b, f, r, v;
cin >> n;
while (n--) {
cin >> b >> f >> r >> v;
B[b - 1][f - 1][r - 1] += v;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 10; k++) {
cout <<" ";
cout << B[i][j][k];
}
cout << endl;
}
if (i < 3) {
cout << "####################" << endl;
}
}
return 0;
}