题解 | #查找兄弟单词#

查找兄弟单词

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

import java.util.*;
public class Main {
    static Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        int n = in.nextInt();
        String[] srr = new String[n];
        for (int i = 0; i < n; i ++ ) 
            srr[i] = in.next();
        String x = in.next();
        int k = in.nextInt();
        int cnt = 0;
        List<String> list = new ArrayList<>();
        for (String str : srr) {
            if (isBrother(str, x)) {
                cnt ++ ;
                list.add(str);
            }
        }
        System.out.println(cnt);
        if (list.size() >= k) {
            list.sort((a, b)->a.compareTo(b));
        System.out.println(list.get(k - 1));
        }
        
    }
    static boolean isBrother(String a, String b) {
        if (a.equals(b) || a.length() != b.length()) 
            return false;
        char[] c1 = a.toCharArray();
        char[] c2 = b.toCharArray();
        Arrays.sort(c1);
        Arrays.sort(c2);
        return String.valueOf(c1).equals( String.valueOf(c2));
    }
}
全部评论

相关推荐

合适才能收到offe...:项目岗是什么岗?我看你有段好像跟策划运营相关,如果找运营的话第三段经历写详细点儿。 个人建议是把自我评价删了换成专业技能放在工作经验上或者下面。学生会那个也可以删,把第一个包装成店铺运营,写4-6给点。第三个也是写4-6个点。注意工作内容➕部分数据。 投递的时候BOS招呼用语改一下,换成我有xx工作经验,熟练掌握xx技能样式,也可以简历截图然后直接发送。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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