1338 - Hidden Secret!
Time Limit: 1 second(s) Memory Limit: 32 MB
In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:
- You can change some uppercase letters to lower case and vice versa.
- You can add/remove spaces freely.
- You can permute the letters.
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
Output for 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
Case 1: Yes
Case 2: Yes
Case 3: No
简单的字符串模拟
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
char str[1000], str_1[1000];
char a[1000], b[1000];
int main()
{
int T;int yy = 0;
scanf("%d",&T);
getchar();
for(int j = 1;j <= T; j++) {
memset(str,0,sizeof(str));
memset(str_1,0,sizeof(str_1));
memset(a,0,sizeof(a));
memset(a,0,sizeof(a));
gets(str);
gets(str_1);
int len_1 = strlen(str); int len_2 = strlen(str_1);
int z, k; z = 0; k = 0;
for(int i = 0;i < len_1; i++) {
if(str[i] != ' ') {
if(str[i]>='A' && str[i]<='Z') {
a[k] = str[i]+32;
}
else a[k] = str[i];
k++;
}
}
for(int i = 0;i < len_2; i++) {
if(str_1[i]!=' ') {
if(str_1[i]>='A'&&str_1[i]<='Z') {
b[z] = str_1[i]+32;
}
else b[z] = str_1[i];
z++;
}
}
bool flag = true;
// int n = strlen(a);int m = strlen(b);
sort(a,a+k); sort(b,b+z);
// printf("%s\n",a);printf("%s",b);
for(int i = 0;i < max(z,k); i++) {
if(a[i]!=b[i]) {
flag = false; break;
}
}
if(flag) printf("Case %d: Yes\n",j);
else printf("Case %d: No\n",j);
}
return 0;
}