首页 > 其他 > 详细

LightOJ 1338

时间:2016-05-02 11:47:57      阅读:203      评论:0      收藏:0      [点我收藏+]
B - B
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

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;
}

 

LightOJ 1338

原文:http://www.cnblogs.com/handsomecui/p/5452034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!