zjnu 1744 EKSPLOZIJA(模拟栈)

EKSPLOZIJA
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 45 Accepted: 12

Description

Mirko likes to play with strings of characters, but this time he has taken it too far – he put an “explosion” in the string! An explosion is a series of characters which, if found in the vicinity of fire, explodes and starts a chain reaction. Mirko, being as negligent as he usually is, forgot that his string contained an explosion and placed it near a candlelight. Thus the chain reaction began. The chain reaction takes place in the following way:

• if a string contains explosions, they all explode and a new string is formed by concatenating the pieces without the exploding parts

• this concatenation could possibly create new explosions

• the chain reaction repeats while there are explosions in the string

Now Mirko wants to know whether anything will be left after this series of chain reactions. If nothing remains, output “FRULA” (without quotes). If, by any chance, something is left, output the final string remaining after all the reactions.

Please note: The explosion will not contain two equal characters.

Input

The first line of input contains Mirko's string, (1 ≤ |Mirko's string| ≤ 1 000 000). The second line of input contains the explosion string, (1 ≤ |explosion| ≤ 36). Both Mirko's string and the explosion string consist of uppercase and lowercase letters of the English alphabet and digits 0, 1, … 9.

Output

The first and only line of output must contain the final string remaining after all the reactions as stated in the task.

Sample Input

 
 
12ab112ab2ab 12ab

Sample Output

 
 
FRULA

Hint

Firstly, the bombs on positions 1 and 6 explode. Then we are left with ****1****2ab (where * marks the character that exploded) and when that string is put together, we get 12ab. Sadly, that is an explosion all over again so it disappears.


这题就是给你两个字符串,问你字符串一里面把所有字符串都删除还剩下什么

我就是模拟栈做得。。

AC代码:

/* ***********************************************
Author        :yzkAccepted
Created Time  :2016/3/19 20:57:06
TASK		  :。.cpp
LANG          :C++
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef __int64 ll;
const int maxn=1000010;
char st[maxn],s[maxn],g[maxn];
char ans[maxn];
int main()
{
	int i,j,k;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	memset(s,0,sizeof(s));
	memset(st,0,sizeof(st));
	memset(g,0,sizeof(g));
	memset(ans,0,sizeof(ans));
    scanf("%s",s+1);
	int n=strlen(s+1);
	scanf("%s",g+1);
	int m=strlen(g+1);
	int rear=0;
	int flag=1;
	for(i=1;i<=n;i++)
	{
		st[++rear]=s[i];
		
		if(rear>=m && st[rear]==g[m])
		{
			flag=1;
			for(j=1;j<=m;j++)
			{
				if(st[rear-m+j]!=g[j])
				{
					flag=0;
					break;
				}
			}
			if(flag==1)
				rear-=m;
		}
		
	}
	for(i=1;i<=rear;i++)
		ans[i]=st[i];
	if(rear==0)
		printf("FRULA\n");
	else
		printf("%s\n",ans+1);
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值