c++ map数据结构比较同义词去重,转换排除
来源:互联网 发布:软件开发实施方案 编辑:程序博客网 时间:2024/05/18 02:00
方便大家.日后需要,可以找的到!#include "stdafx.h"#include<map>#include<vector>#include<string>#include<fstream>using namespace std;string& replace_all_distinct(string& str,const string& old_value,const string& new_value) { for(string::size_type pos(0); pos!=string::npos; pos+=new_value.length()) { if( (pos=str.find(old_value,pos))!=string::npos ) str.replace(pos,old_value.length(),new_value); else break; } return str; }//截取字符void ExtractSubString(std::string strSource, char ch, std::vector<std::string>& vString){int nBegin = 0;int nEnd = 0;nEnd = strSource.find(ch, nBegin);while (nEnd != -1){vString.push_back(strSource.substr(nBegin, nEnd - nBegin));nBegin = nEnd + 1;nEnd = strSource.find(ch, nBegin);}if ( nBegin < strSource.length()){vString.push_back(strSource.substr(nBegin,strSource.length()-nBegin));}}void HandleDate(){//读文件std::string m_Pro_Path = "C:/Users/Administrator/Desktop/同义词库/同义词.txt";char pBuf[4024]={0};FILE * pFill = fopen(m_Pro_Path.c_str(),"r");std::map<std::string,std::string> mapurl;if(pFill){int nLine = 0;while( fgets(pBuf,4024,pFill)!=NULL ){nLine++;std::string strLine(pBuf);std::vector<std::string> vString;ExtractSubString(strLine, ',', vString);if ( vString.size()<2){continue;}std::string strFirst = vString.at(0);if ( strFirst.find("十一") != string::npos){std::string ss = strLine;std::vector<std::string> vString1;ExtractSubString(strLine, ',', vString1);}std::string strSecond = vString.at(1);strFirst = replace_all_distinct(strFirst,"\t","");strFirst = replace_all_distinct(strFirst,"\n","");strSecond = replace_all_distinct(strSecond,"\t","");strSecond = replace_all_distinct(strSecond,"\n","");if( mapurl.find(strFirst) == mapurl.end()){mapurl.insert(std::map<std::string,std::string>::value_type(strFirst,strSecond));}if( mapurl.find(strSecond) == mapurl.end()){mapurl.insert(std::map<std::string,std::string>::value_type(strSecond,strFirst));}}}//写到文件std::map<std::string, std::string>::iterator it;std::string strBuffer = "";for (it = mapurl.begin(); it != mapurl.end(); ++it){strBuffer += it->first.c_str();strBuffer += ',';strBuffer += it->second.c_str();strBuffer += "\r\n";}FILE *fp = fopen("C:/Users/Administrator/Desktop/同义词库/后处理同义词.txt", "wt+");if (fp == NULL)return;fwrite((char*)strBuffer.c_str(), strBuffer.size(), 1, fp);fclose(fp);}int main(){HandleDate();return 0;}
阅读全文
0 0
- c++ map数据结构比较同义词去重,转换排除
- codeforces 651C(map、去重)
- List<Map>去重
- list<map<String ,object>> 去重,list map去重
- 用map实现去重
- map 遍历 ListBuffer去重
- linux排序去重比较
- linux排序去重比较
- 比较两个List去重
- c++vector去重
- JAVA数组去重和JavaScript数组去重比较
- List<Map<String,Object>>去重,排序
- List<Map<String,Object>>去重,排序
- List元素字符串放入Map去重
- 不同方法数组去重的比较
- 字符串比较大小 并且去重
- Java 数据结构之List去重
- 【重学数据结构】数制转换
- io流
- Robotframework环境搭建
- HTMl5的存储方式sessionStorage和localStorage详解
- mysql 安装
- Android画图相关。取高度宽度,画矩形。
- c++ map数据结构比较同义词去重,转换排除
- S5PV210系列 (裸机十)之按键和CPU的中断系统(一)
- Kotlin-------------Android 开发一级语言
- Gym
- AFNetWorking相关设置
- Windows中的管道解析
- 浅谈“比特币勒索病毒”
- 欢迎使用CSDN-markdown编辑器
- mdev的基本工作原理