4880211_wa.cpp

来自「部分PKU上的源码」· C++ 代码 · 共 134 行

CPP
134
字号
#include<iostream>
#include<string>
using namespace std;
int n,m;
struct place
{
	string in,out;
}qp[55];
struct zs
{
	string in,out;
	bool used;
}qz[55];
char in[1000];
bool match(int &count)
{
	int i,j;
	int temp;
	for(i=0;i<n;i++)
	{
		temp=count;
		for(j=0;j<qp[i].in.length();j++)
		{
			if(in[temp]!=qp[i].in[j])
			{
				break;
			}
			else temp++;
		}
		if(j==qp[i].in.length())
		{
			cout<<qp[i].out;
			count+=qp[i].in.length();
			return true;
		}
	}
	for(i=0;i<m;i++)
	{
		temp=count;
		for(j=0;j<qz[i].in.length();j++)
		{
			if(in[temp]!=qz[i].in[j])
			{
				break;
			}
			else temp++;
		}
		if(j==qz[i].in.length()&&!qz[i].used)
		{
			cout<<qz[i].out<<" ("<<qz[i].in<<")";
			qz[i].used=true;
			count+=qz[i].in.length();
			return true;
		}
	}
	return false;
}
int main()
{
	cin>>n>>m;
	int i,j;

	for(i=0;i<n;i++)
	{
		getchar();
		scanf("%[^\n]",in);
		j=0;
		while(in[j]!='\"') j++;
		j++;
		while(in[j]!='\"')
		{
			qp[i].in+=in[j];
			j++;
		}
		j++;
		while(in[j]!='\"') j++;
		j++;
		while(in[j]!='\"')
		{
			qp[i].out+=in[j];
			j++;
		}
	}
	for(i=0;i<m;i++)
	{
		getchar();
		scanf("%[^\n]",in);
		j=0;
		while(in[j]!='\"') j++;
		j++;
		while(in[j]!='\"')
		{
			qz[i].in+=in[j];
			j++;
		}
		j++;
		while(in[j]!='\"') j++;
		j++;
		while(in[j]!='\"')
		{
			qz[i].out+=in[j];
			j++;
		}
		qz[j].used=false;
	}
	getchar();
	while(1)
	{
		int state=scanf("%[^\n]",in);
		if(state==EOF)break;
		if(state==0) ;
		else
		if(in[0]=='#') 
		{
			cout<<"#";
			for(i=0;i<m;i++) qz[i].used=false;
		}
		else
		{
			j=0;
			string word;
			while(in[j])
			{
				if(!match(j))
				{
					cout<<in[j];j++;
				}
			}
		}
		getchar();
		cout<<endl;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?