题解 | #查找兄弟单词#

查找兄弟单词

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        int num = fzhinput.nextInt();
        ArrayList<String> zd= new ArrayList<>();
        ArrayList<String> brothers = new ArrayList<>();
        for(int i =0;i<num;i++){
            zd.add(fzhinput.next());
        }
        String cxdx = fzhinput.next();
        int index = fzhinput.nextInt();
        int count;
        for(String da : zd){
            if(da.length()!=cxdx.length()||da.equals(cxdx)){
                
            }
            else{
                char word[] = da.toCharArray();
                char mbword[] = cxdx.toCharArray();
                Arrays.sort(word);
                Arrays.sort(mbword);
                boolean result = Arrays.equals(word,mbword);
                if(result){
                    brothers.add(da);
                }

            }
        }
        Collections.sort(brothers);
        
        System.out.println(brothers.size());
        if (index <= brothers.size()) {
            System.out.println(brothers.get(index - 1));
        }    
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-27 14:11
很喜欢小米的新车,校招薪资每月22k,攒多久能买?
测试糕手手:别看工资,先看现金流存款。有50W存款以上再考虑,车是消耗品,选适合自己的重要。你有钱就当我没说过
点赞 评论 收藏
分享
Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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