题目摘要:There once was a champion of WoW
Arthasdk the name he was bestowed
He Death Gripped you to his side
His Chains of Ice stopped your stride
And Obliterates made you say"OWW!"
But one day our hero got puzzled
His Death Grip totally fizzled
In his darkest despair
He could barely hear
"OMG NOOB u Chains of Iced than u DeathGripped"
输入输出要求:
Input:
You are given a recording of the abilitiesour hero used in his battles.
The first line of input will contain asingle integer n (1 <= n <= 100), the number of battles our hero played.
Then follow n lines each with a sequence ofki (1 <= ki <= 1000) characters, each of which are either 'C', 'D' or'O'. These denote the sequence of abilities used by our hero in the i-thbattle. 'C' is Chains of Ice, 'D' is Death Grip and 'O' is Obliterate.
Output:
Output the number of battles ourhero won, assuming he won each battle where he did not Chains of Iceimmediately followed by Death Grip.
题目大意:Death Knight Hero有三个技能,他要进行n场战斗,如果他放完技能C然后立刻放技能D,那么他就会输。要求计算他能赢的场数。
输入输出样例:
Sample Input
3
DCOOO
DODOCD
COD
Sample Output
2
解题思路:对每个字符串都扫一遍,如果有CD那么赢的场数减一。
代码:
#include<iostream>#include<string>
#include<cstring>
using namespace std;
char str[1005];
int Judge()
{
int i;
for(i=0;i<strlen(str)-1;i++)
{
if((str[i]=='C')&&(str[i+1]=='D'))
return 1;
}
return 0;
}
int main()
{
int N;
while(cin>>N)
{
int sum=N;
while(N--)
{
cin>>str;
if(Judge())
sum--;
}
cout<<sum<<endl;
}
return 0;
}
解题感想:简单水题