题解 | #单词识别# 笨方法

单词识别

https://www.nowcoder.com/practice/16f59b169d904f8898d70d81d4a140a0

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int panduan(char buchongfu[1000][20],int k,char danci[20]){
    int i=0;
    for(i=0;i<k;i++){
        if(strcmp(buchongfu[i],danci)==0){
            return i;
        }
    }
    return -1;
}
int main()
{
    char shuru[1000];
    char danci[1000][20];
    int num[1000]={0};
    gets(shuru);
    int i=0;
    int j=0,k=0;
    while(shuru[i]!='.'){
        while(shuru[i]!=' ' && shuru[i]!='.'){
            if(shuru[i]>='A'&&shuru[i]<='Z'){
                shuru[i]=(char)(shuru[i]-'A'+'a');
            }
            danci[j][k++]=shuru[i++];

        }
        if(shuru[i]==' '){
            danci[j][k]='\0';
            i++;
            j++;
            k=0;
        }

    }

    int count=j+1;
    char buchongfu[1000][20];
    k=0;
    for(i=0;i<count;i++){
        if(panduan(buchongfu,k,danci[i])>=0){
            num[panduan(buchongfu,k,danci[i])]++;
        }
        else{
           strcpy(buchongfu[k],danci[i]);
           num[k++]++;
        }
    }
    char tmp[20];
    for(i=0;i<k-1;i++){
        for(j=i+1;j<k;j++){
            if(strcmp(buchongfu[i],buchongfu[j])>0){
                int temp=num[i];
                num[i]=num[j];
                num[j]=temp;
                strcpy(tmp,buchongfu[i]);
                strcpy(buchongfu[i],buchongfu[j]);
                strcpy(buchongfu[j],tmp);
            }
        }
    }
    for(i=0;i<k;i++){
        printf("%s:%d\n",buchongfu[i],num[i]);
    }

    return 0;
}

全部评论

相关推荐

07-10 11:08
门头沟学院 Java
投递京东等公司9个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 10:39
一个证都没&nbsp;我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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