题目
在DOTA2中,乞求者卡尔可以召唤三种元素,冰(Quas),雷(Wex),火(Exort),当你按下Q时,他会召唤一个冰元素,按下W召唤雷元素,按下E召唤火元素。所有元素总数量最大为3,这意味着当你已经拥有了3个任意元素时,若你再召唤一个元素,则最先召唤出的元素会消失,新元素诞生。与此同时,他还有一个技能-元素祈唤®。元素祈唤可以根据你当前拥有的各类元素数量施放不同的技能,施放技能后,元素并不会消失,当元素数量不足三个的时候不能施放出技能。更详细解释请看样例说明。请你根据卡尔的操作,打印出他放了什么技能,若不能施放出技能,则输出” FFFFFFFK”。技能列表如下图所示:
输入格式:
一个只包含QWER的字符串,且长度不超过10^6。
输出格式:
每次卡尔按下R,就输出一个答案,每个答案占一行。
输入样例:
EERERWRWRWRR
输出样例:
FFFFFFFK
Sun Strike
Chaos Meteor
Alacrity
EMP
EMP
提示:
状态没有顺序,比如WEE和EWE和EEW是相同的
在第一次使用R时,卡尔的状态为EE,并不能用出技能。
在第二次使用R时,卡尔的状态为EEE,能够使用Sun Strike
在第三次使用R时,卡尔的状态为EEW,能够使用Chaos Meteor
在第四次使用R时,卡尔的状态为EWW,能够使用Alacrity
在第五次使用R时,卡尔的状态为WWW,能够使用EMP
在第六次使用R时,卡尔的状态为WWW,能够使用EMP
代码
#include <iostream>
#include <string>
using namespace std;
string t="";
void print()
{
int len=t.length();
if(len<3)
{
cout<<"FFFFFFFK"<<endl;
return;
}
if(len>3)
{
string::iterator it=t.begin()+3;
t.erase(it,t.end());
}
if(t.find("WWW")<len)
cout<<"EMP"<<endl;
else if(t.find("QQQ")<len)
cout<<"Cold Snap"<<endl;
else if(t.find("EEE")<len)
cout<<"Sun Strike"<<endl;
else if(t.find("QWW")<len || t.find("WWQ")<len || t.find("WQW")<len)
cout<<"Tornado"<<endl;
else if(t.find("WWE")<len || t.find("EWW")<len || t.find("WEW")<len)
cout<<"Alacrity"<<endl;
else if(t.find("QQE")<len || t.find("QEQ")<len || t.find("EQQ")<len)
cout<<"Ice Wall"<<endl;
else if(t.find("QEE")<len || t.find("EQE")<len || t.find("EEQ")<len)
cout<<"Forge Spirit"<<endl;
else if(t.find("WEE")<len || t.find("EWE")<len || t.find("EEW")<len)
cout<<"Chaos Meteor"<<endl;
else if(t.find("QQW")<len || t.find("WQQ")<len || t.find("QWQ")<len)
cout<<"Ghost Walk"<<endl;
else
cout<<"Deafening Blast"<<endl;
}
int main()
{
string s;
cin>>s;
int len=s.length();
for(int i=0;i<len;i++)
{
if(s[i]=='R')
print();
else
{
string::iterator it=t.begin();
t.insert(it,s[i]);
}
}
return 0;
}
分析
- 运用string对象
- 运用find函数,erase函数,insert函数,迭代器