题解 | #查找兄弟单词#

查找兄弟单词

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

#include<stdio.h>
#include<string.h>
int main(void)
{
    int n;
    scanf("%d",&n);
    char str[1000][10];
    char str2[1000][10];
    int i=0;
    for(int i=0;i<n;i++)
    {
        scanf("%s",&str[i]);
    }
    char x[10];
    scanf("%s",&x);
    int k;
    scanf("%d",&k);
    int len=strlen(x);
    int cnt=0;
    int flag=0;
    int ii=0;
    for(i=0;i<n;i++)
    {
        if(strlen(str[i])==len&&strcmp(str[i],x)!=0)
        {
            int map[26]={0};
            for(int j=0;j<len;j++)
            {
                map[str[i][j]-'a']++;
                map[x[j]-'a']--;
            }
            for(int m=0;m<26;m++)
            {
                if(map[m]!=0)
                {
                    flag=1;
                }
            }
            if(flag==0)
            {
                cnt++;
                strcpy(str2[ii++],str[i]);
            }
            flag=0;         
        }
    }
     printf("%d\n",cnt);
    //排序
    for(i=0;i<cnt-1;i++)
    {
        for(int j=0;j<cnt-1-i;j++)
        {
            if(strcmp(str2[j+1],str2[j])<0)
            {
                char temp[10];
                strcpy(temp,str2[j+1]);
                strcpy(str2[j+1],str2[j]);
                strcpy(str2[j],temp);
            }
        }
    }
   
     printf("%s\n",str2[k-1]);
   
    return 0;
}
全部评论

相关推荐

冲鸭2024:亚信不去也罢
投递亚信科技(中国)有限公司等公司6个岗位
点赞 评论 收藏
分享
孙艹肘:校招不给三方直接让实习我都去了,,主打一个在学校呆着也是闲着,不如出来实习一下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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