CCF题目-模板生成系统 希望大神帮我看看为啥始终是90分~~

敌敌畏口狗 2018-03-05 11:09:52

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>

using namespace std;

int string_replace(string &s1, const string &s2, const string &s3)
{
string::size_type pos = 0;
string::size_type a = s2.size();
string::size_type b = s3.size();
while ((pos = s1.find(s2,pos)) != string::npos)
{
s1.replace(pos, a, s3);
pos += b;
}
return 0;
}
int main()
{
int m = 0 ,n = 0 ,count = 0,countn = 0;
vector<string>temp;
vector<string>no;
map<string,string>info;
map<string,string>::iterator it;
cin>>m>>n;
getchar();
while(count!=m)
{
string res;
getline(cin,res);
//if (!res.empty())
//{
temp.push_back(res);
count++;
//}
}
while(countn!=n)
{
string res;
getline(cin,res);
if (!res.empty())
{
string nre,re;
int index = 0;
for(int i = 0;i < res.length()-1;i++)
{
if(res[i] == '"')
{
index = i;
}
}
nre = res.substr(0,index-1);
re = res.substr(index+1,res.length()-index-2);
info.insert(pair<string, string>("{{ "+nre+" }}", re));
countn++;
}

}
//cout << "input finished!\n";
//找到无定义的变量,字典值设为空串
for(int i = 0;i < m;i++)
{
string res = temp[i];
if(res.length() == 0) continue;
if(res.length() < 7) continue;
for(int j = 0;j <res.length()-4;j++)
{
int s_pos = 0,e_pos = 0,mcount = 0;
string argu;
if(res[j]=='{'&&res[j+1]=='{')
{
s_pos = j+3;
for(int k = s_pos;k < res.length();k++)
{
if(res[k] == ' ')
{
e_pos = k;
break;
}
}
}
argu = res.substr(s_pos,e_pos-s_pos);
for(it = info.begin();it!=info.end();it++)
{
if(argu != it->first)
{
mcount+=1;
}
}
if(mcount == info.size())
{
if(!argu.empty())
{
argu = "{{ "+argu+" }}";
no.push_back(argu);
}
}
else
{
continue;
}
}
}


for(it = info.begin();it!=info.end();it++)
{
for(int i = 0;i < m;i++)
{
string_replace(temp[i],it->first,it->second);
}
}
for(int i = 0;i < no.size();i++)
{
for(int j = 0;j < m;j++)
{
string_replace(temp[j],no[i],"");
}
}
for(int i = 0;i < m;i++)
{
cout<<temp[i]<<endl;
}
return 0;
}
...全文
499 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43840062 2018-12-15
  • 打赏
  • 举报
回复
请问是怎么什么造成了超时
敌敌畏口狗 2018-03-10
  • 打赏
  • 举报
回复
问题解决了 谢谢

64,666

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧