# include<stdio.h>
# include<algorithm>
# include<sstream>
# include<iostream>
# include<string>
# include<stdlib.h>
# include<time.h>
using namespace std;
string mould[110];
string var[110];
string str_value[110];
string str_name[110];
stringstream ss;
int main()
{
// freopen("data.txt","r",stdin);
int m,n;
scanf("%d%d",&m,&n);
getchar();
char temp[110];
for(int i=0;i<m;i++)
{
gets(temp);
mould[i] = temp;
}
for(int i =0;i<n;i++)
{
gets(temp);
var[i] = temp;
ss.str(var[i]);
ss>>str_name[i];
int len = str_name[i].size();
str_value[i] = var[i].substr(len+1,110);
str_value[i].erase(str_value[i].begin());
str_value[i].erase(str_value[i].end()-1);
}
for(int i=0;i<m;i++)
{
int pos = mould[i].find("{{ ");
while(pos!=string::npos)
{
bool find = false;
int pos_r = mould[i].find(" }}",pos);
int len = pos_r - pos + 3;
int len_name = pos_r - (pos+3);
string temp = mould[i].substr(pos+3,len_name);
int j;
for( j = 0;j<n;j++)
{
if(temp == str_name[j])
{
find = true;
mould[i].replace(pos,len,str_value[j]);
break;
}
}
if(!find)
{
mould[i].erase(pos,len);
pos = mould[i].find("{{ ",pos+1);
}
else
{
pos = mould[i].find("{{ ",pos+str_value[j].size()-1);
}
}
}
for(int i=0;i<m;i++)
{
cout<<mould[i]<<endl;
}
return 0;
}
CCF CSP 201509-3 满分AC
最新推荐文章于 2024-11-22 18:54:57 发布