Lightoj1338——Hidden Secret!(模拟)

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 10001
using 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值