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

📄 en.cpp

📁 打开文件
💻 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 + -