There is a string s of length 3 or greater. No two neighboring characters in s are equal.
Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:
Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.
The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
Constraints
3≤|s|≤105
s consists of lowercase English letters.
No two neighboring characters in s are equal.
Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:
Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.
The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.
Constraints
3≤|s|≤105
s consists of lowercase English letters.
No two neighboring characters in s are equal.
输入
The input is given from Standard Input in the following format:
s
s
输出
If Takahashi will win, print First. If Aoki will win, print Second.
样例输入
aba
样例输出
Second
提示
Takahashi, who goes first, cannot perform the operation, since removal of the b, which is the only character not at either ends of s, would result in s becoming aa, with two as neighboring.
题意就是给一个字符串,判断是否能由空串经四个串组合得到
直接用substr()函数或者erease()进行函数剪切最后判断空串即可
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string s;
string a="dream";
string b="dreamer";
string c="erase";
string d="eraser";
while (cin>>s)
{
int flag;
int n;
while (1)
{
flag=0;
n=s.length();
if (n==0)
{
flag=1;
break;
}
if (n>=5)
{
if(s.compare(n-5,n,a)==0)
{
s=s.substr(0,n-5);
flag=1;
}
if(s.compare(n-5,n,c)==0)
{
s=s.substr(0,n-5);
flag=1;
}
if (n>=6)
{
if(s.compare(n-6,n,d)==0)
{
s=s.substr(0,n-6);
flag=1;
}
if (n>=7)
{
if(s.compare(n-7,n,b)==0)
{
s=s.substr(0,n-7);
flag=1;
}
}
}
}
if(flag==0)break;
}
if (flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}