Lightoj1338——Hidden Secret!(模拟)

来源:互联网 发布:js中使用java变量 编辑:程序博客网 时间:2024/05/13 06:51

In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:

  1. You can change some uppercase letters to lower case and vice versa.
  2. You can add/remove spaces freely.
  3. 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
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
Output for Sample Input
Case 1: Yes
Case 2: Yes
Case 3: No

主要是题意看了好久才懂。。。。
其实就是求两串字符串的字母是否一样,部分大小写

#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <cmath>#include <algorithm>#define INF 0x3f3f3f3f#define MAXN 2005#define Mod 10001using namespace std;char a[MAXN],b[MAXN];int aa[MAXN],bb[MAXN];bool check(char &a){    if(a>='a'&&a<='z')    {        a-=32;        return true;    }    if(a>='A'&&a<='Z')        return true;    return false;}int main(){    int t,cnt=1;    scanf("%d",&t);    getchar();    while(t--)    {        gets(a);        gets(b);        memset(aa,0,sizeof(aa));        memset(bb,0,sizeof(bb));        int lena=strlen(a),lenb=strlen(b);        for(int i=0; i<lena; ++i)        {            if(check(a[i]))                aa[a[i]-'A']++;        }        for(int i=0; i<lenb; ++i)        {            if(check(b[i]))                bb[b[i]-'A']++;        }        bool flag=true;        for(int i=0;i<26;++i)            if(bb[i]!=aa[i])                flag=false;        printf("Case %d: ",cnt++);        if(flag)            printf("Yes\n");        else            printf("No\n");    }    return 0;}
0 0