LightOJ 1338

B - B

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status Practice LightOJ 1338

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;
}
时间: 2024-08-27 18:52:23

LightOJ 1338的相关文章

lightoj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

LightOJ 1030 Discovering Gold【概率】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题意:基础概率题. 代码: #include <stdio.h> #include <string.h> #include <vector> #include <string> #include <algorithm> #include <iostream> #include <iterator>

LightOJ - 1370 Bi-shoe and Phi-shoe

题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题目大意:给N个数a[i], N <= 1e6,问使 Φ(x) >= a[i] 成立的最小x的所有x的和是多少. 解题思路:我们知道的是对于素数 m 来说,phi[m] = m - 1.另一方面,对于一个合数 m 来说, phi[m] < phi[x] , x > m && x 是素数. 因此,我们可以认为,每

lightoj 1057 - Collecting Gold(状压dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1057 题解:看似有点下记忆话搜索但是由于他是能走8个方向的也就是说两点的距离其实就是最大的x轴或y轴的差.然后只有15个藏金点状压一下加dfs就行了. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0X3f3f3f

Lightoj 1088 - Points in Segments 【二分】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1088 题意: 有一维的n个点和q条线段.询问每条线段上的点有多少个: 思路:寻找这些点中对于每条线段的上下界即可. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include

Lightoj 1090 - Trailing Zeroes (II)

题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1090 题目大意: 给出n,r,p,q四个数字1<=n,r,p,q<=1000000,求出的末尾有几个0? 解题思路: 是不是一下子懵了,数字好大,复杂度好高,精度怎么办···············,就问你怕不怕? 因为你是Acmer,这都不应该是问题.因为10的因子只有2和5,所以可以打表保存从1到当前数字相乘的积中分别含有2,5的个数.然后算出中分别含有2,5的个数,

暑期训练狂刷系列——Lightoj 1084 - Winter bfs

题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1084 题目大意: 有n个点在一条以零为起点的坐标轴上,每个点最多可以移动k,问最终能不能把所有点都聚集在大于等于三个点的集合里面,如果能最少需要几个这样的集合? 解题思路: 刚开始看到题目感觉好简单,就开始了sort然后贪心之旅,这就是错误的开始.最后发现这样并不行,然后再Alex的提醒下想用单调队列优化,在我愚昧的理解下竟然写成了bfs,提交竟然ac了,surprise~

LightOJ - 1148 - Mad Counting

先上题目: 1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to

LightOJ 1013 LCS+记忆化搜索

http://www.lightoj.com/volume_showproblem.php?problem=1013 题目大意: 给两个字符串,问最短的满足子串包含给的两个字符串的字符串的最短长度,以及最短长度的字符串的个数. 第一个问题就是简单的LCS,两个串长度和减去公共部分. 第二个问题要进行记忆话搜索来查找.dp(i,j,l)(第一个串i位,第二个串j位,总串l位) 转移方程 dp(i,j,l) = dp(i-1,j-1,l-1) (s1[i] = s2[j]时) dp(i,j,l) =