题解 | #查找兄弟单词#

查找兄弟单词

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count=in.nextInt();//
        String[] strs=new String[count];
        for(int i=0;i<count;i++)
        {
            strs[i]=in.next();
        }
        String x=in.next();
        int index=in.nextInt();
        ArrayList<String> browords=new ArrayList<>();
        for(int i=0;i<strs.length;i++)
        {
            if((!strs[i].equals(x))&&strs[i].length()==x.length())
            {
                char[] chStr=x.toCharArray();//对比!
                char[] word=strs[i].toCharArray();//
                int temp=0;
                for(int j=0;j<chStr.length;j++)
                {
                    for(int j2=0;j2<word.length;j2++)
                    {
                        if(word[j]==chStr[j2])
                        {
                            chStr[j2]='0';
                            temp++;
                            break;
                        }

                    }
                }
                if(temp==chStr.length)
                {
                    browords.add(strs[i]);
                }
            }
        }
        System.out.println(browords.size());
        if(index>0&&index<browords.size())
        {
            Collections.sort(browords);
            System.out.println(browords.get(index-1));
        }

        // 注意 hasNext 和 hasNextLine 的区别
      

    }
}

//1、兄弟有哪些、以及按序输出第一个---》只,。

//需要sort输出第一个

//2、那个相同、不同------?只用比较所有的字母是否相同且长度相同

是否相同,一个字母一个字母的比较,两层for循环

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:16
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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