004-008-005
Multidimensional Array: Weekly Points Table
Easy
Problem Description
Multidimensional Array: Weekly Points Table
Learning Objective: Manage numeric data with 2D array and implement aggregation processing
Manage weekly point card earning records. Create 2D array to record point earnings by combination of day and store (3 stores).
Test Cases
※ Output examples follow programming industry standards
Input:
2 10 20 30 15 25 35
Expected Output:
=== Weekly Points === Day 1: A:10pt B:20pt C:30pt = 60pt Day 2: A:15pt B:25pt C:35pt = 75pt Total: 135pt (2 days)
Input:
1 50 40 30
Expected Output:
=== Weekly Points === Day 1: A:50pt B:40pt C:30pt = 120pt Total: 120pt (1 days)
Input:
3 10 10 10 20 20 20 30 30 30
Expected Output:
=== Weekly Points === Day 1: A:10pt B:10pt C:10pt = 30pt Day 2: A:20pt B:20pt C:20pt = 60pt Day 3: A:30pt B:30pt C:30pt = 90pt Total: 180pt (3 days)
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
⌄
⌄
⌄
⌄
⌄
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// ユーザー入力を読むためのキーボードからの入力を読むScannerオブジェクトを作成
Scanner sc = new Scanner(System.in);
// ユーザーからの入力値を読んで格納
int n = sc.nextInt();
int[][] points = new int[n][3];
// アイテムをループして処理
for (int i = 0; i < n; i++) {
// アイテムをループして処理
for (int j = 0; j < 3; j++) {
// ユーザーからの入力値を読んで格納
points[i][j] = sc.nextInt();
}
}
// コンソール経由でユーザーに出力を表示
System.out.println("=== Weekly Points ===");
String[] stores = {"A", "B", "C"};
int grandTotal = 0;
// アイテムをループして処理
for (int i = 0; i < n; i++) {
// コンソール経由でユーザーに出力を表示
System.out.print("Day " + (i + 1) + ": ");
int dayTotal = 0;
// アイテムをループして処理
for (int j = 0; j < 3; j++) {
// コンソール経由でユーザーに出力を表示
System.out.print(stores[j] + ":" + points[i][j] + "pt ");
dayTotal += points[i][j];
grandTotal += points[i][j];
}
// コンソール経由でユーザーに出力を表示
System.out.println("= " + dayTotal + "pt");
}
// コンソール経由でユーザーに出力を表示
0 B / 5 MB
You have 10 free executions remaining
