Encrypting passwords is one of the most important problems nowadays, and you trust only the encryp-
tion algorithms which you invented, and you have just made a new encryption algorithm.
Given a password which consists of only lower case English letters, your algorithm encrypts this
password using the following 3 steps (in this given order):
1.
Swap two different characters of the given password (you can do this step zero or more times).
2.
Append zero or more lower case English letters at the beginning of the output of step one.
3.
Append zero or more lower case English letters to the end of the output of step two.
And the encrypted password is the output of step three.
You have just nished implementing the above algorithm and applied it on many passwords. Now
you want to make sure that there are no bugs in your implementation, so you decided to write another
program which validates the output of the encryption program. Given the encrypted password and the
original password, your job is to check whether the encrypted password may be the result of applying
your algorithm on the original password or not.
Input
Your program will be tested on one or more test cases. The rst line of the input will be a single
integer
T
, the number of test cases (1
T
100). Followed by the test cases, each test case is on two
lines. The rst line of each test case contains the encrypted password. The second line of each test case
contains the original password. Both the encrypted password and the original password are at least 1
and at most 100,000 lower case English letters (from `
a
' to `
z
'), and the length of the original password
is less than or equal the length of the encrypted password.
Output
For each test case, print on a single line one word, `
YES
' (without the quotes) if applying the algorithm on
the original password may generate the encrypted password, otherwise print `
NO
' (without the quotes).
SampleOutput
3
abcdef
ecd
cde
ecd
abcdef
fed
SampleOutput
YES
YES
NO//有坑
 
 
 
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int hash[maxn];
int cur[maxn];
char s[],t[];
int h[];
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
memset(h,,sizeof(h));
memset(hash,,sizeof(hash));
memset(cur,,sizeof(cur));
memset(t,,sizeof(t));
memset(s,,sizeof(s));
scanf("%s",t);
getchar();
scanf("%s",s);
getchar();
int len1=strlen(s);
int len2=strlen(t); for(int i=; i<len1; i++)
{
int temp=s[i];
hash[temp]++;
} int ans=;
int cnt=;
bool flag=false;
if(len1==len2)
{
for(int i=; i<len2; i++)
{
int d=t[i];
h[i]=d;
if(cur[d]<hash[d])
cnt++;
cur[d]++;
if(cnt==len1){
flag=true;
break;
}
}
} else
{
for(int i=; i<len2; i++)
{ int d=t[i];
h[i]=d;
if(cur[d]<hash[d])
cnt++;
cur[d]++; if(i>=len1)
{
d=h[i-len1];
if(cur[d]<=hash[d])
cnt--;
cur[d]--; }
if(cnt==len1){
flag=true;
break;
} }
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
 
 
 
 
 

哈希UVALive 6326 Contest Hall Preparation的更多相关文章

  1. UVaLive 2796 Concert Hall Scheduling (最小费用流)

    题意:个著名的音乐厅因为财务状况恶化快要破产,你临危受命,试图通过管理的手段来拯救它,方法之一就是优化演出安排,既聪明的决定接受或拒绝哪些乐团的演出申请,使得音乐厅的收益最大化.该音乐厅有两个完全相同 ...

  2. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  3. HUNNU--湖师大--11407--It Is Cold

    [F] It Is Cold Dr. Ziad Najem is known as the godfather of  the  ACPC. When the regional contest was ...

  4. 【取对数】【哈希】Petrozavodsk Winter Training Camp 2018 Day 1: Jagiellonian U Contest, Tuesday, January 30, 2018 Problem J. Bobby Tables

    题意:给你一个大整数X的素因子分解形式,每个因子不超过m.问你能否找到两个数n,k,k<=n<=m,使得C(n,k)=X. 不妨取对数,把乘法转换成加法.枚举n,然后去找最大的k(< ...

  5. 【字符串哈希】The 16th UESTC Programming Contest Preliminary F - Zero One Problem

    题意:给你一个零一矩阵,q次询问,每次给你两个长宽相同的子矩阵,问你它们是恰好有一位不同,还是完全相同,还是有多于一位不同. 对每行分别哈希,先一行一行地尝试匹配,如果恰好发现有一行无法对应,再对那一 ...

  6. UVALive - 6893 The Big Painting 字符串哈希

    题目链接: http://acm.hust.edu.cn/vjudge/problem/129730 The Big Painting Time Limit: 5000MS 题意 给你一个模板串和待匹 ...

  7. UVALive - 4671 K-neighbor substrings (FFT+哈希)

    题意:海明距离的定义:两个相同长度的字符串中不同的字符数.现给出母串A和模式串B,求A中有多少与B海明距离<=k的不同子串 分析:将字符a视作1,b视作0.则A与B中都是a的位置乘积是1.现将B ...

  8. HDU 6326.Problem H. Monster Hunter-贪心(优先队列)+流水线排序+路径压缩、节点合并(并查集) (2018 Multi-University Training Contest 3 1008)

    6326.Problem H. Monster Hunter 题意就是打怪兽,给定一棵 n 个点的树,除 1 外每个点有一只怪兽,打败它需要先消耗 ai点 HP,再恢复 bi点 HP.求从 1 号点出 ...

  9. 2016 Asia Jakarta Regional Contest L - Tale of a Happy Man UVALive - 7722

    UVALive - 7722 一定要自己做出来!

随机推荐

  1. An error occurred at line: 1 in the generated java file问题处理

    tomcat6启动后,加载jsp页面报错,提示无法将jsp编译为class文件,主要报错信息如下: An error occurred at line: 1 in the generated java ...

  2. 循环语句:LOOP,WHILE和数字式循环

    一 简单循环 1 语法: LOOP      要执行的语句;      EXIT WHEN <条件语句> --条件满足,退出循环语句  END LOOP; 2 例子: DECLARE    ...

  3. HDU 2047 EOF牛肉串

    水到不想整理,线性DP #include <algorithm> #include <iostream> #include <cstring> #include & ...

  4. python3爬取咪咕音乐榜信息(附源代码)

    参照上一篇爬虫小猪短租的思路https://www.cnblogs.com/aby321/p/9946831.html,继续熟悉基础爬虫方法,本次爬取的是咪咕音乐的排名 咪咕音乐榜首页http://m ...

  5. C语言进阶——浮点数的秘密03

    浮点数在内存中的储存方式为:符号位 指数位 尾数 float和double类型的数据在计算机内部的表实方法是一样的,但是由于所占的存贮空间的不同,其分别能表示的数值范围和精度不同. 类型 f符号位 指 ...

  6. springboot搭建环境访问Controller层返回404

    如果启动成功,但是却访问不了你自己写的controller,报404错误,那么原因就是您写的controller没有被spring 容器扫描到 解决方案: spring boot 默认扫描您的类是 在 ...

  7. [Bzoj3252]攻略(dfs序+线段树)

    Description 题目链接 Solution 可以想到,每次肯定是拿最大价值为最优 考虑改变树上一个点的值,只会影响它的子树,也就是dfs序上的一个区间, 于是可以以dfs序建线段树,这样就变成 ...

  8. CentOS网络设置 couldn't resolve host 'mirrorlist.centos.org问题解决

    在VMWare上安装好centos后,使用yum安装nodejs报错:can not resolve host 'mirritlist.centos.org', 百度上很多都说在/etc/resolv ...

  9. c语言的左移、右移

    先说左移,左移就是把一个数的所有位都向左移动若干位,在C中用<<运算符.例如: int i = 1; i = i << 2;  //把i里的值左移2位 也就是说,1的2进制是0 ...

  10. MySQL单表查询语句练习题

    /*1. 查询出部门编号为30的所有员工*/ /* 分析: 1). 列:没有说明要查询的列,所以查询所有列 2). 表:只一张表,emp 3). 条件:部门编号为30,即deptno=30 */ ; ...