OMG(绝望版 2021-10-28 19:59 采纳率: 100%
浏览 35
已结题

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])]);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • CSDN专家-link 2021-10-28 20:22
    关注

    分数应该考虑0分,所以分数范围是0-100,所以数组元素应该有101个。

    评论
  • OMG(绝望版 2021-10-28 20:00
    关注

    不是运行超时,就是答案错误

    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月8日
  • 已采纳回答 10月31日
  • 创建了问题 10月28日

悬赏问题

  • ¥15 PCL注册的选点等函数如何取消注册
  • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
  • ¥15 Python爬虫程序
  • ¥15 crypto 这种的应该怎么找flag?
  • ¥15 代码已写好,求帮我指出错误,有偿!
  • ¥15 matlab+波形匹配算法
  • ¥15 转录组分析做聚类树图时癌旁组被分到了癌组
  • ¥15 大一Python字典
  • ¥15 multisim电路设计(相关搜索:设计报告)
  • ¥15 PC-lint Plus