just 泡泡
2021-11-06 18:39
采纳率: 100%
浏览 45

java写的程序提交时出现了运行超时问题,想问问我这个代码还能改不

本人刚学习不久,只会一些基础的东西,希望别弄特别深奥的东西,我怕看不懂
后面有代码和PTA上的运行结果截图。


import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(),i;
        StringBuilder[] num1 = new StringBuilder[N];
        int [] num2 = new int[N],num3 = new int[N];
        for (i = 0; i < N; i++) {
            num1[i] = new StringBuilder(sc.next());
            num2[i] = sc.nextInt();
            num3[i] = sc.nextInt();
        }
        int M = sc.nextInt();
        int[] cxnum2 = new int[M];
        for (i = 0; i < M; i++) {
            cxnum2[i] = sc.nextInt();
            for (int j = 0; j < N; j++) {
                if (cxnum2[i] == num2[j]) {
                    System.out.println(num1[j] + " " + num3[j]);
                }
            }
        }
    }
}

img

img

2条回答 默认 最新

相关推荐 更多相似问题