帮忙排排错
昨天参加学校的编程比赛,有几道题怎么也通过不了,大家帮忙看下是什么问题
/////////////////////////////////////////////////////////////////////
/*
Given a string of uppercase letters, is it possible to erase one or
more characters to get the string 'BUAA'?
输入
The first line contains a single integer T(1<=T<=15), the number of
test cases.
Each test case is a single line containing at least 1 and at most
100 uppercase letters.
There are no spaces, TABs, lowercase letters or other characters
before, or after the string.
输出
For each test case, print the case number and 'Yes' if it is possible
to get 'BUAA', or 'No' otherwise.
The output is case-sensitive, so don't output 'YES' or 'yes' when
'Yes' should be output.
样例输入
4
ACMBUAA
ACMAAUB
HELLOWORLD
BUACMA
样例输出
Case 1: Yes
Case 2: No
Case 3: No
Case 4: Yes
*/
/////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
void WorkOut(char word[], char buaa[]);
int main()
{
int i, n;
char word[200];
char buaa[5] = "BUAA";
cin >> n;
for (i = 0; i < n; i++)
{
cin >> word;
cout << "Case " << i + 1;
WorkOut(word, buaa);
}
return 0;
}
void WorkOut(char *word, char *buaa)
{
int i = 0, j = 0;
bool find = false;
while (word[i] != '\0')
{
if (word[i] == buaa[j])
{
j++;
i++;
}
else
i++;
if (buaa[j] == '\0')
{
cout << ": Yes " << endl;
find = true;
break;
}
}
if (!find)
cout << ": No " << endl;
}
////////////////////////////////////////////////////////////////////////
/*
给的测试项都行,但是也许有什么情况没考虑到,帮忙想一下吧
*/
//////////////////////////////////////////////////////////////////////
[[it] 本帖最后由 andyzhshg 于 2008-4-6 19:35 编辑 [/it]]