QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607279#8932. BingoUESTC_NLNS#Compile Error//Java82.2kb2024-10-03 14:34:202024-10-03 14:34:22

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 14:34:22]
  • 评测
  • [2024-10-03 14:34:20]
  • 提交

answer

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt(); // Number of test cases
        sc.nextLine(); // Consume newline

        for (int i = 0; i < t; i++) {
            String[] input = sc.nextLine().split(" ");
            String n1 = input[0];
            String m1 = input[1];

            BigInteger n = new BigInteger(n1);
            BigInteger m = new BigInteger(m1);

            // Case 1: if n < m, simply output m
            if (n.compareTo(m) < 0) {
                System.out.println(m);
                continue;
            }

            // a1 is the smallest multiple of m larger than n
            BigInteger a1 = (n.divide(m).add(BigInteger.ONE)).multiply(m);
            String a1Str = a1.toString();

            // Increment n by 1 and check if m is present in n1
            n = n.add(BigInteger.ONE);
            n1 = n.toString();
            if (n1.contains(m1)) {
                System.out.println(n1);
                continue;
            }

            int lm = m1.length();

            // Prepare for the next part of the calculation
            String n21 = n1.substring(0, n1.length() - 2 * lm - 3);
            String n2 = n1.substring(n1.length() - 2 * lm - 3);
            String nine = "9";
            String a2 = nine.repeat(n2);

            for (int j = 0; j <= n2.length() - lm; j++) {
                String a3 = n2.substring(0, j) + m1 + "0".repeat(n2.length() - lm - j);
                if (a3.compareTo(n2) >= 0) {
                    a2 = (new BigInteger(a2).compareTo(new BigInteger(a3)) < 0) ? a2 : a3;
                }
            }

            a2 = n21 + a2;

            // Compare the lengths and print the result
            if (a1Str.length() < a2.length()) {
                System.out.println(a1Str);
            } else if (a2.length() < a1Str.length()) {
                System.out.println(a2);
            } else {
                System.out.println(a1Str.compareTo(a2) < 0 ? a1Str : a2);
            }
        }
        sc.close();
    }
}

詳細信息

Main.java:43: error: cannot find symbol
            String a2 = nine.repeat(n2);
                            ^
  symbol:   method repeat(String)
  location: variable nine of type String
Main.java:46: error: cannot find symbol
                String a3 = n2.substring(0, j) + m1 + "0".repeat(n2.length() - lm - j);
                                                         ^
  symbol:   method repeat(int)
  location: class String
2 errors