标签:
Description
In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:
And if two names match exactly, then you can say that one name is hidden into another.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with two lines. Each line contains a name consists of upper/lower case English letters and spaces. You can assume that the length of any name is between 1 and 100 (inclusive).
Output
For each case, print the case number and "Yes" if one name is hidden into another. Otherwise print "No".
Sample Input
3
Tom Marvolo Riddle
I am Lord Voldemort
I am not Harry Potter
Hi Pretty Roar to man
Harry and Voldemort
Tom and Jerry and Harry
Sample Output
Case 1: Yes
Case 2: Yes
Case 3: No
判断第一个串是否包含第二个串,可以交换位置,改变大小写。。。
代码:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; template<typename T> bool is_lower(T x){ if(x >= ‘a‘ && x <= ‘z‘)return true; return false; } template<typename T> void dispose(T *s){ T *a; a = (T *)malloc(sizeof(s)); int i, j; for(i = 0, j = 0; s[i]; i++){ if(s[i] == ‘ ‘ || s[i] == ‘\t‘)continue; a[j++] = is_lower(s[i]) ? s[i] : ‘a‘ + s[i] - ‘A‘; // printf("%c %c\n", s[i], a[j - 1]); } a[j] = 0; strcpy(s, a); } template<typename T> bool js(T *m, T *s){ int i, j; for(i = 0, j = 0; m[i] && s[i]; i++){ if(m[i] == s[j])j++; } if(s[j])return false; return true; } int main(){ int T, kase = 0; scanf("%d", &T); char mstr[110], str[110]; getchar(); while(T--){ gets(mstr);gets(str); dispose(mstr);dispose(str); sort(mstr, mstr + strlen(mstr)); sort(str, str + strlen(str)); if(js(mstr, str)) printf("Case %d: Yes\n", ++kase); else printf("Case %d: No\n", ++kase); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5452034.html