⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmm.cpp

📁 刚上文机器翻译课
💻 CPP
字号:
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    ifstream infile;
    infile.open("E:\\随便玩玩\\正向最大匹配\\dict.txt");
    vector<string>  ChDic;
    string word;
    string text="中国是一个美丽的国家";
    vector<string>arr;
    //load dict 
    while(getline(infile,word ))
    {         
       ChDic.push_back(word);         
    }   
    
    string temp = text; 
    string temp1 = temp;
   int p1 = 0; 
  while(strlen(temp1.c_str())!=0)
   { 
     for(int i=strlen(temp1.c_str());i>=0;i=i-2)
    {
       if(find(ChDic.begin(),ChDic.end(),temp)!=ChDic.end())
        {
         temp +="|";       
         arr.push_back(temp);
         p1 = i ;                               
         break;
        }              
      else
       {
         temp = temp1.substr(0,i-2);   
       }          
    }  
      temp1 = temp1.substr(p1); 
      temp = temp1;
    
   }
    for(vector<string>::iterator iter=arr.begin();iter!=arr.end();++iter)
    {
       cout <<*iter;
    } 
    cout <<endl;
    infile.close();
    system("pause");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -