Chinaunix首页 | 论坛 | 博客
  • 博客访问: 264843
  • 博文数量: 45
  • 博客积分: 930
  • 博客等级: 准尉
  • 技术积分: 553
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-22 17:53
文章分类

全部博文(45)

文章存档

2013年(5)

2012年(40)

分类: C/C++

2012-07-03 13:57:48


点击(此处)折叠或打开

  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <map>

  6. using namespace std;

  7. int main(int argc,char * argv[])
  8. {
  9.     if (argc < 4)
  10.     {
  11.         cout<<"parameters ERROR"<<endl;
  12.         cout<<"Usage: " << argv[0]<<" DIC inFile outFile"<<endl;
  13.         return EXIT_FAILURE;
  14.     }

  15.     map<string, string> wordDic;
  16.     
  17.     ifstream ftin(argv[1]);
  18.     if (!ftin)
  19.     {
  20.         cout<<argv[1] <<" does\'s exit, please check it"<<endl;
  21.         return EXIT_FAILURE;
  22.     }
  23.     
  24.     string curLine;
  25.     string curWord;
  26.     istringstream isstream;
  27.     while (getline(ftin,curLine))
  28.     {
  29.         isstream.str(curLine);
  30.         string phnSer;
  31.         isstream >> curWord;
  32.         string tmpPhn;
  33.         while(isstream >> tmpPhn)
  34.             phnSer += tmpPhn + ' ';
  35.         wordDic[curWord] = phnSer;
  36.         isstream.clear();
  37.     }
  38.     ftin.close();

  39.     ifstream fin(argv[2]);
  40.     if (!fin)
  41.     {
  42.         cout<<argv[2] <<" does\'s exit, please check it"<<endl;
  43.         return EXIT_FAILURE;
  44.     }
  45.     ofstream fout(argv[3]);
  46.     while (getline(fin,curLine))
  47.     {
  48.         if (curLine.find(".lab") != string::npos){
  49.             string nextLine;
  50.             getline(fin,nextLine);
  51.             string outLine;
  52.             while(nextLine.find('.') != 0)
  53.             {
  54.                 if(wordDic.find(nextLine) != wordDic.end())
  55.                     outLine += wordDic[nextLine] + " ";
  56.                 else
  57.                     cout<<argv[1]<<"doesn\'t has item: "<<nextLine<<endl;
  58.                 getline(fin,nextLine);
  59.             }
  60.             fout<<outLine<<endl;    
  61.         }
  62.     
  63.     }
  64.     fin.close();
  65.     return EXIT_SUCCESS;
  66. }

阅读(1272) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~