CSP:CSP认证考试:202104-1(灰度直方图)满分答案,Java版
作者:互联网
CSP:CSP认证考试:202104-1(灰度直方图)满分答案,Java版
一、题目:
二、Java满分答案
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String[] num = str.split(" ");
ArrayList<Integer> ints = new ArrayList<>();
for (String x : num) {
ints.add(Integer.parseInt(x));
}
int n = ints.get(0);
int L = ints.get(2);
int[] result = new int[L];
for (int i = 0; i < L; i++) {
result[i] = 0;
}
for (int i = 0; i < n; i++) {
str = scanner.nextLine();
num = str.split(" ");
for (String x : num) {
result[Integer.parseInt(x)] = result[Integer.parseInt(x)] + 1;
}
}
for (int i = 0; i < L-1; i++) {
System.out.print(result[i]+" ");
}
System.out.print(result[L-1]);
}
}
标签:String,int,直方图,num,灰度,result,ints,CSP 来源: https://blog.csdn.net/XRT_knives/article/details/121725463