题解 | #查找兄弟单词#

查找兄弟单词

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));
        }    
    }
}

全部评论

相关推荐

02-26 15:33
已编辑
西北大学 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务