lightoj 1338 - Hidden Secret! (字符串

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:

  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
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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值