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. 使用筛法在 O(logN) 的时间内查询多组数的素数因子

    Prime Factorization using Sieve O(log n) for multiple queries 使用筛法在 O(logN) 的时间内查询多组数的素数因子 前言 通常, 我们 ...

  2. 5.Spring Cloud初相识-------Hystrix熔断器

    前言: 1.介绍Hystrix 在一个分布式系统里,许多依赖不可避免的会调用失败,比如超时.异常等,如何能够保证在一个依赖出问题的情况下,不会导致整体服务失败,这个就是Hystrix需要做的事情.Hy ...

  3. web的监听器,你需要知道这些...

    一.简介 Listener是Servlet规范的另一个高级特性,它用于监听java web程序的事件,例如创建.修改.删除session,request,context等,并触发相应的处理事件,这个处 ...

  4. Spring整合JUnit spring静态对象属性的注入

    package cn.itcast.d_junit4; import org.junit.Test; import org.junit.runner.RunWith; import org.sprin ...

  5. DateTools,可能是最好用的iOS日期工具库

    项目简介 DateTools 用于提高Objective-C中日期和时间相关操作的效率.灵感来源于 DateTime和Time Period Library. 项目主页: DateTools 最新示例 ...

  6. 爬虫学习(十一)——bs4基础学习

    ba4的介绍: bs4是第三方提供的库,可以将网页生成一个对象,这个网页对象有一些函数和属性,可以快捷的获取网页中的内容和标签 lxml的介绍 lxml是一个文件的解释器,python自带的解释器是: ...

  7. Linux Centos 通过虚拟用户访问FTP的配置

    Linux Centos 通过虚拟用户访问FTP的配置 实验需求: 让下面4个虚拟用户使用系统用户ftpvu的权限来连接到Linux FTP服务器,并确保都锁定在 自己的虚拟用户目录,不能切换到其他目 ...

  8. Target runtime Apache Tomcat v8.5 is not defined.

    Target runtime Apache Tomcat v8.5(或者其它版本) is not defined. 这个错误通常是在从文件夹中导入别人的项目的时候发生,因为 在 .setting 中有 ...

  9. (servlet页面跳转没有反应)

    问题:页面跳转到/UserManager/LoginCLServlet,就一直没有反应,无法继续执行下去(servlet页面跳转没有反应) 解决: doPost()方法里面必须写成这样 正确的写法:  ...

  10. PHP 基础知识总结

    PHP 代表 PHP: Hypertext Preprocessor PHP 文件可包含文本.HTML.JavaScript代码和 PHP 代码 PHP 代码在服务器上执行,结果以纯 HTML 形式返 ...