首页 > 其他 > 详细

STL CodeForces - 190C

时间:2021-08-25 08:39:53      阅读:26      评论:0      收藏:0      [点我收藏+]

原题链接
考察:dfs
错误思路:
??有点类似\(acwing\)的正则问题,然而并不是....
正确思路:
??当遇到一个pair后面一定是<,但是\(int\)不一定.需要考虑它在pair后的哪个位置.很巧妙的方法是一个pair< , >三个符号\(2\)\(dfs\).,是第一个dfs回溯后添加,>是第二个dfs后添加.

Code

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int N = 100010;
int n,cnt,i;
string s,ans;
bool ok;
void dfs()
{
	if(cin>>s)
	{
		ans+=s;
		if(s=="pair")
		{
			ans+="<";
			dfs();
			ans+=",";
			dfs();
			ans+=">";
		}
	}
}
int main()
{
	scanf("%d",&n);
	dfs();
	if(cin>>s||ans.find("<,")!=ans.npos||ans.find(",>")!=ans.npos) puts("Error occurred");
	else printf("%s\n",ans.c_str());
	return 0;
}

STL CodeForces - 190C

原文:https://www.cnblogs.com/newblg/p/15183080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!