码迷,mamicode.com
首页 > 其他好文 > 详细

词频统计

时间:2016-09-05 21:00:28      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>
#include<vector>
#include<string>
#include<map>    
#include<iostream>
using namespace std;
#define MAXN 1000000
char str[MAXN];
map<string,int> ma;
map<string,int>::iterator it;
int main()
{
    gets(str);
    int len = strlen(str);
    for(int i = 0;i<len;i++)
    {
        if(str[i]!= )
        {
            string s;
            for(;i<len;i++)
            {
                if(str[i]!= )
                          s+=str[i];
                else break;
            }
            ma[s]++;
        }
        
    }
    for(it=ma.begin();it!=ma.end();it++)
    {
        cout<<it->first<<" "<<it->second<<endl;
    }
    return 0;
}

 

词频统计

标签:

原文地址:http://www.cnblogs.com/liqiao085/p/5843507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!