Time Limit: 1 Sec Memory Limit:
128 MB
Submit: 75 Solved: 21
每组实例包含一个长度不超过100的字符串且仅含有英文字母。
WxhepsQissb
END
heissb
刚开始没有考虑到删除字符后会出现新的不符合要求的字符串,wa了一次,好坑,
每次遍历字符串,发现不符合要求的就不管,但是如果删除得有字符串,那么就有可能出现新的,所以要再判断一遍知道遍历一次字符串,没有发现不符合要求的字符串
#include
#include
#include
using namespace std;
int main()
{
char str[1010],b[1010];
while(scanf("%s",str)!=EOF)
{
if(strcmp(str,"END")==0) break;
int flog=0;
while(true)
{
flog=0;
int l=0;
for(int i=0;i<strlen(str);i++)
{
if((str[i]=='W'&&str[i+1]=='X')||(str[i]=='W'&&str[i+1]=='x')||(str[i]=='w'&&str[i+1]=='X')||(str[i]=='w'&&str[i+1]=='x'))
{i+=1,flog=1;continue;}
else if
(
(str[i]=='P'&&str[i+1]=='S'&&str[i+2]=='Q')||
(str[i]=='P'&&str[i+1]=='S'&&str[i+2]=='q')||
(str[i]=='P'&&str[i+1]=='s'&&str[i+2]=='Q')||
(str[i]=='P'&&str[i+1]=='s'&&str[i+2]=='q')||
(str[i]=='p'&&str[i+1]=='S'&&str[i+2]=='Q')||
(str[i]=='p'&&str[i+1]=='S'&&str[i+2]=='q')||
(str[i]=='p'&&str[i+1]=='s'&&str[i+2]=='Q')||
(str[i]=='p'&&str[i+1]=='s'&&str[i+2]=='q'))
{i+=2,flog=1;continue;}
else b[l++]=str[i];
}
b[l]='\n';
if(!flog)
break;
memset(str,'\0',sizeof(str));
for(int j=0;j<l;j++)
str[j]=b[j];
memset(b,'\0',sizeof(b));
}
printf("%s\n",str);
}
return 0;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章