?? en.cpp
字號:
// en.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include<iostream>
#include <map>
#include <vector>
#include <fstream>
#include<string>
using namespace std;
int main()
{
ifstream infile;
infile.open("2.txt");
vector<string> vec;
//ofstream out;
//out.open("a.txt"); 輸出到一個文件里
int cxz=0;
while(!infile.eof())
{
string cixing = "";
vector<int> sta; //定義向量
string str ; //用來存放從文本中讀出的字符串
getline(infile,str);//讀取文件中的第一行,并存放到str 中
cout<<str<<endl;
for(int i = 0;i < str.length();i++)
{
string s = str.substr(i,1);
if(s=="(")
{
sta.push_back(i);
}
if(s==")")
{
int local = sta.at(sta.size()-1);
sta.pop_back();
string s1 = str.substr(local+1,i-local-1);//含有一條單詞和詞性的字符串
if(s1.find("(") == string::npos)//在整條字符串中找不到 ( 就執行 if
{
int nb=1; //記錄詞性出現的次數
int kong = s1.find(" "); //記住詞性后面空格的位置
string pos = s1.substr(0,kong); //用pos記錄詞性
int poslocal = cixing.rfind(pos+"-"); //尋找詞性+“-”
if(poslocal != string::npos) //如果找到重復的詞性則執行if
{
int s1=cixing.find("-",poslocal); //查找該詞性出現的次數
int kong1=cixing.find(" ",s1); //查找詞性出現次數后面的空格
string sz=cixing.substr(s1+1,kong1); //記錄詞性出現的次數
nb = atoi(sz.c_str()); //將本是字符串的次數改為整形
nb++;
string shuchu=cixing.substr(poslocal,kong1);
}
char j[2];
itoa(nb,j,10);
pos= pos + "-"+j+" ";
cixing = cixing + pos;
}
}
}
cout<<cixing<<endl;
int a=cixing.find(" ");
while(a!=string::npos)
{
string fcx=cixing.substr(0,a);
vec.push_back(fcx);
cixing=cixing.substr(a+1);
a=cixing.find(" ");
}
infile.close();
//out.file 輸出到文件里
}
ifstream infile1;
infile1.open("3.txt");
vector<int> sta2; //定義向量
string str2 ;
getline(infile1,str2);
cout<<str2<<endl;
string zcixing="";
for(int m = 0;m < str2.length();m++)
{
string ss=str2.substr(m,1);
if(ss=="(")
{
sta2.push_back(m);
}
if(ss==")")
{
int local1 = sta2.at(0);
string ss1 = str2.substr(local1+1,m-local1-1);
sta2.pop_back();
int mh=ss1.find(":");
string szq=ss1.substr(0,mh);
string szh=ss1.substr(mh+1);
int szq1,sz1;
szq1 = atoi(szq.c_str());
sz1 = atoi(szh.c_str());
if(sz1!=0)
{ string vecs=vec.at (szq1-1);
int g=vecs.find("-");
string zcx=vecs.substr(0,g);
zcx=zcx+"-"+szh+" ";
zcixing=zcixing+zcx;
}
}
}
int b=zcixing.find(" ");
map<int, string> cx;
map<int, string> ::iterator cx1;
int a=0;
while(b!=string::npos)
{
string cx3=zcixing.substr(0,b);
int g1=cx3.find("-");
string cx4=cx3.substr(0,g1);
string cx5=cx3.substr(g1+1);
a = atoi(cx5.c_str());
cx[a]=cx4;
zcixing=zcixing.substr(b+1);
b=zcixing.find(" ");
}
for(cx1=cx.begin();cx1!=cx.end() ;cx1++)
{
cout<<(*cx1).second<<"-"<<(*cx1).first<<" ";
}
cout<<endl;
infile.close();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -