P391--一个单词转换的map
2014-11-16 22:13
357 查看
#include <iostream> #include <map> #include <fstream> #include <string> #include <sstream> #include <vector> #define FAILED 1 #define SUCCESS 0 using namespace std; bool convert2Map(ifstream &inf, map<string, string> &ru); bool emprassSecret(ifstream &inf, vector<vector<map<string, string>::mapped_type>> &svvec, map<string, string> &ru); int main() { ifstream inf1("rule.txt"); if (!inf1) { cout << "Open the file is error" << endl; return FAILED; } map<string, string> rules; convert2Map(inf1, rules); ifstream inf2("secret.txt"); if (!inf1) { cout << "Open the file is error" << endl; return FAILED; } vector<vector<map<string, string>::mapped_type>> svvec; emprassSecret(inf2, svvec, rules); for (auto svec : svvec) { for (auto s : svec) { cout << s << " "; } cout << endl; } return SUCCESS; } bool convert2Map(ifstream &inf, map<string, string> &ru) { string line; while (getline(inf, line)) { auto pos = line.find(' '); if (pos + 1 >= line.size()) { return FAILED; } string s1(line, 0, pos); string s2(line, pos + 1); ru.insert(map<string, string>::value_type(s1, s2)); } return SUCCESS; } bool emprassSecret(ifstream &inf, vector<vector<map<string, string>::mapped_type>> &svvec, map<string, string> &ru) { string line; vector<vector<string>> temp; while (getline(inf, line)) { istringstream record(line); string s; vector<string> svec; while (record >> s) { svec.push_back(s); } temp.push_back(svec); } for (const auto &v: temp) { vector<map<string, string>::mapped_type> svec; for (const auto &s : v) { if (ru.count(s)) { svec.push_back(ru[s]); } else { svec.push_back(s); } } svvec.push_back(svec); } return SUCCESS; }
相关文章推荐
- c++ primer 一个单词转换的map(自定义版)
- C++Primer第11章 一个单词转换的map【程序】
- 一个单词转换的map
- C++ Primer : 第十一章 : 关联容器示例: 一个单词转换的map
- 如何将一个map 转换成json数据
- Bean-Query 一个把对象转换为Map的Java工具库
- c++学习笔记-map的使用实例(单词转换)
- 如何将一个List<Map<String,String>>类型的集合数据转换成json格式输出
- 一个运用map的文本转换程序
- 一个简单的例子理解C++ map, 运用map统计单词出现的次数
- C++ Primer 第十章 10.3.9 “单词转换”map对象
- c++学习笔记——个单词转换的map程序详解
- 一个利用map统计一段英文文章中每个单词出现次数的小程序
- c++学习笔记——个单词转换的map程序详解
- C++ 10.3.9 "单词转换"map对象
- 给定一个单词集合,找出可以相互转换的集合。比如abc bca cba都可以相互转换(变位词)
- 单词转换(map对象)
- 使用map实现单词转换的程序
- 一个简单的例子理解C++ map, 运用map统计单词出现的次数
- C++ primer 单词转换(使用map对象)