[003]Hidden CUGB
Time Limit: 1000 ms Memory Limit: 65536 KBDescription
Given a string of uppercase letters, is it possible to erase ONE OR MORE characters to get the string 'CUGB'?
Input
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 50 uppercase letters. There are no spaces, TABs, lowercase letters or other characters
before or after the string.
Output
For each test case, print the case number and 'Yes' if it is possible to get 'CUGB', or 'No' otherwise. The output is case-sensitive, so don't output 'YES' or 'yes' when 'Yes' should be output.
Sample Input
4
ACMICPCCUGB
ACMICCP
HELLOWORLD
CXXUXXGXXBXX
ACMICPCCUGB
ACMICCP
HELLOWORLD
CXXUXXGXXBXX
Sample Output
Case 1: Yes
Case 2: No
Case 3: No
Case 4: Yes
题目大意:
Case 2: No
Case 3: No
Case 4: Yes
给出一个字符串,判断这个字符串能否通过删除某些字符使得剩余的字符串为CUGB,如果可以,输出Yes并标明是第几组,如果不可以,输出No并标明是第几组。
注意:特殊情况,如果字符串就是CUGB则不用删除字符,此时应该输出No。
代码如下:
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,n,T;
char str[100],str1[4]={'C','U','G','B'};
scanf("%d",&T);
for(i=1;i<=T;i++)
{
scanf("%s",str);
n=strlen(str);
for(k=0,j=0;j<n;j++)
{
if(str[j]==str1[k])
k++;
}
if(k==4&&n>4)
printf("Case %d: Yes\n",i);
else
printf("Case %d: No\n",i);
}
return 0;
}