关于 CodeChef 上的 "Uncle Johnny" 个问题_

regarding "Uncle Johnny" problem_ on CodeChef

www.codechef.com

上有一道练习题 Uncle Johny

作为一个冗长的,我提供link。

https://www.codechef.com/problems/JOHNY/

我有两个解决该问题的方法(代码 1 和代码 2)

代码 1

class UncleJohny
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br = new BufferedReader(newInputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        int test_case = Integer.parseInt(br.readLine());

        while(test_case-- > 0)
        {
            int n = Integer.parseInt(br.readLine());

            int i = 0;

            String a[] = br.readLine().split(" ");   //Mind this line

            int k = Integer.parseInt(br.readLine());

            String temp = a[k - 1];

            Arrays.sort(a);

            pw.println(Arrays.binarySearch(a, temp) + 1);
        }

        pw.flush();
    }
}

代码 2

class UncleJohny
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        int test_case = Integer.parseInt(br.readLine());

        while(test_case-- > 0)
        {
            int n = Integer.parseInt(br.readLine());

            int a[] = new int[n];

            int i = 0;

            for(String str: br.readLine().split(" "))
            {
                a[i++] = Integer.parseInt(str);     //Mind this line
            }

            int k = Integer.parseInt(br.readLine());

            int temp = a[k - 1];

            Arrays.sort(a);

            pw.println(Arrays.binarySearch(a, temp) + 1);
        }

        pw.flush();
    }
} 

上述代码中的基本任务是在排序后

中找到输入数组atemp值的索引

根据我的说法,这两种代码的输出不会有任何差异。 (如果我错了请纠正我)

CodeChef 正在接受 Code 2,但对 Code 1

错误答案

我的查询到底是什么?

尽管相同,为什么 code 2 被接受而 code 1 不被接受?

为什么我需要将输入值存储在 int 数组中(如代码 2 所示)而不是将它们存储到 String 数组中(如代码 1 所示),以便获得我的回答被接受了吗?

整数的排序顺序与字符串的排序顺序不同。例如。 “1”<“10”<“2”...