题解 | #查找兄弟单词#

查找兄弟单词

https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        int len = in.nextInt();
        String[] arr = new String[len];
        for (int i = 0; i < len; i++) {
            arr[i] = in.next();
        }
        String word = in.next();
        char[] wordChar = word.toCharArray();
        Arrays.sort(wordChar);
        int index = in.nextInt();
        String k = "";
        int count = 0;
        Arrays.sort(arr);
        for (int i = 0; i < len; i++) {
            String str = arr[i];
            char[] strChar = str.toCharArray();
            Arrays.sort(strChar);

            if (!Arrays.equals(wordChar, strChar)) {
                continue;
            }
            if (word.equals(str)) {
                continue;
            }
            count++;
            if (count == index) {
                k = str;
            }
        }
        
        System.out.println(count);
        System.out.print(k);
    }
}

全部评论

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
点赞 评论 收藏
分享
06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务