-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
46 lines (36 loc) · 1.08 KB
/
Main.java
File metadata and controls
46 lines (36 loc) · 1.08 KB
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
37
38
39
40
41
42
43
44
45
46
package recruit.byte01;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 1.读数据
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] userLikes = new int[n];
for (int i = 0; i < n; i++) {
userLikes[i] = in.nextInt();
}
int q = in.nextInt();
int[][] querySet = new int[q][3];
for (int i = 0; i < q; i++) {
for (int j = 0; j < 3; j++) {
querySet[i][j] = in.nextInt();
}
}
in.close();
StringBuilder builder = new StringBuilder();
for (int[] query : querySet) {
builder.append(compute(userLikes, query)).append("\n");
}
System.out.println(builder.toString().trim());
}
// 计算人数
private static int compute(int[] userLikes, int[] query) {
int count = 0;
for (int i = query[0] - 1; i < query[1]; i++) {
if (userLikes[i] == query[2]) {
count++;
}
}
return count;
}
}