zoukankan      html  css  js  c++  java
  • 词频统计

    SSH:git@git.coding.net:jlspduqiao/word-frequency-count.git

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    typedef struct LNode
    {
        char c[20];
        int count;
        struct LNode *next;
    }LNode,*LinkList; 
    
    struct LNode *Create()
    {
        LinkList L;
        L=(LinkList)malloc(sizeof(LNode));
        L->next=NULL; 
        return L;
    }
    
    void Print(LinkList L)  
    {  
        struct LNode *p;   
        p = L->next;  
        if(p!= NULL)  
        {   
            do  
            {   
                printf ("%s   %d   
    ", p->c, p->count);  
                p = p->next; 
            }  
            while (p != NULL);  
        }  
    }
    
    bool Find(LinkList &L,char a[20])//查找单词
    {
        LNode *p;
        p=L->next;
        while(p!=NULL)
        {
            if(strcmp(a,p->c)==0){//找到单词
                p->count++;//计数加一
                return true;
            }
            else p=p->next;
        }
        return false;
    }
    
    void Insert(LinkList &L,char a[20])
    {
        LNode *p;
        p=(LinkList)malloc(sizeof(LNode));
        strcpy(p->c,a);
        p->count=1;
        p->next=L->next;
        L->next=p;
    }
    
    int main(){
        struct LNode *L=Create();
        char a[20];
        char c;
        int i=0;
        printf("请输入:
    ");
        while ((c = getchar()) != '
    '){//读入并判断是否输入了回车(回车结束)
            if(c!=' '&&c!='.'&&c!=','&&c!='?'&&c!=':'){
                a[i]=c;
                a[i+1]='';
                i++;
            }
            else{
                if(!Find(L,a))//如果不存在该单词
                    Insert(L,a);
                i=0;
                memset(a,NULL,sizeof(a));
            }
        }
        Print(L);
        return 0;
    }

     运行结果:

        不太会java和c++,试着用链表实现词频统计,看了别的同学的从文件中调用,我感觉自己做错了,需要手动输入,过后会仔细修改一下。

  • 相关阅读:
    JVM基础(一)—— 运行时内存结构
    SQL if 和 case when查询示例
    SQL分组聚合查询
    My music
    DataX增量同步到ADB ADS时报错
    shell find的用法
    pycharm安装
    在两个库中查找出差异明细
    docker下安装centos
    升级RDS8.0遇到的问题
  • 原文地址:https://www.cnblogs.com/duq11/p/5845013.html
Copyright © 2011-2022 走看看