籍n
2021-10-28 19:59
采纳率: 100%
浏览 34
已结题

pat乙级题目,10038Java,运行有两个有错,看不出是哪有错,考虑不全吗?

import java.util.Arrays;
import java.util.Scanner;
public class Main38 {
public static void main(String[] args){
    int[] goadcount = new int[100];
    Arrays.fill(goadcount, 0);
    Scanner sc = new Scanner(System.in);
    int countren = sc.nextInt();
    for(int i = 0;i<countren;i++){
        int grade = sc.nextInt();
        goadcount[grade-1]++;
    }
    int scan = sc.nextInt();
    for(int i = 0;i<scan-1;i++){
        int grade = sc.nextInt();
        System.out.print(goadcount[grade-1]+" ");
    }
    System.out.print(goadcount[sc.nextInt()-1]);
}
}

img

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • CSDN专家-sinJack 2021-10-28 20:11
    最佳回答
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) throws Exception {
            int[] score = new int[101];
            Scanner in=new Scanner(System.in);
            int n =in.nextInt();
            String[] input = in.nextLine().split(" ");
            for (int i = 0; i < n; i++) {
                score[Integer.parseInt(input[i])]++;
            }
            String[] s = in.nextLine().split(" ");
            int k = Integer.parseInt(s[0]);
            for (int i = 0; i < k - 1; i++) {
                System.out.print(score[Integer.parseInt(s[i + 1])] + " ");
            }
            System.out.print(score[Integer.parseInt(s[s.length - 1])]);
        }
    }
    
    评论
    解决 无用 1
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题