【十二题解】 | #查找兄弟单词#

查找兄弟单词

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

#include<stdio.h> #include<string.h> #include<stdlib.h> int cmp(const void *a,const void *b) {

return strcmp(*(char**)a, *(char**)b);

}

int judeg(inta, intb){

for(int i=0; i<128;i++){
    if(a[i] != b[i])return 0;
}
return 1;

}

int brother(chara, charb){

int hash[128]={0};
for(int i=0; a[i]!='\0'; i++)hash[a[i]]++;
int hash2[128]={0};
for(int i=0; b[i]!='\0'; i++)hash2[b[i]]++;
if(strcmp(a, b) != 0 && judeg(hash, hash2)== 1)return 1;
return 0;

}

int main(){

char aa[10]={'d', 'a', 'c', 'b', 'b'};
char bb[10]={'b', 'a', 'c', 'b', 'a'};
int cc = brother(aa, bb);
int number;
while(scanf("%d", &number) != EOF){
    char**data=(char**)malloc(sizeof(char*)*number);
    for(int i=0; i<number; i++){
        data[i]=(char*)malloc(sizeof(char)*10);
        for(int j=0; j<10; j++)data[i][j]='\0';
        scanf("%s", data[i]);
    }
    char name[10]={0};
    scanf("%s", name);
    int hash1[128]={0};
    for(int i=0; name[i]!='\0'; i++)hash1[name[i]]++;
    int number2;
    scanf("%d", &number2);
    qsort(data, number, sizeof(data[0]), cmp);
    int loc =0;
    int all=0;
    for(int i=0; i<number; i++){
        if(brother(name,data[i])){
            all++;
        }
        if(all==number2){
            loc = i;
            all++;
        }
    }
    char*aaa=data[162];
    int aaaa=brother(name, data[162]);
    if(loc==0){
        printf("%d", all);
    }
    else{
         printf("%d\n%s", all-1, data[loc]);
    }
   
}

}

全部评论

相关推荐

一tiao酸菜鱼:秋招还没正式开始呢,就准备有结果了。。。。?
点赞 评论 收藏
分享
深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
只有一个苍穹外卖外加正在看黑马点评,可以找小厂实习吗,还有我的简历有什么大问题吗
Java抽象小篮子:感觉有点熟悉,问题1是学历,2是没实习经历,3是专业技能写得太少太少了(怎么写可以看我置顶帖),4是仅这一个项目找实习不够看。拷打完毕,简历怎么写可以看我置顶帖子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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