博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
哈希UVALive 6326 Contest Hall Preparation
阅读量:5222 次
发布时间:2019-06-14

本文共 3203 字,大约阅读时间需要 10 分钟。

 
 
 
 
 
 
 

 
 
 
 
 
 
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
#include
#include
#include
using namespace std;const int maxn=1000;int hash[maxn];int cur[maxn];char s[100005],t[100005];int h[100005];int main(){ int T; scanf("%d",&T); getchar(); while(T--) { memset(h,0,sizeof(h)); memset(hash,0,sizeof(hash)); memset(cur,0,sizeof(cur)); memset(t,0,sizeof(t)); memset(s,0,sizeof(s)); scanf("%s",t); getchar(); scanf("%s",s); getchar(); int len1=strlen(s); int len2=strlen(t); for(int i=0; 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 0;}

 

 
 
 
 
 

转载于:https://www.cnblogs.com/13224ACMer/p/4692962.html

你可能感兴趣的文章
【转】概要设计怎么写
查看>>
前端编码规范小记
查看>>
C#编程(二十五)----------接口
查看>>
c如何弹出保存路径/保存文件对话框
查看>>
HTML标签二
查看>>
caffe的在ubuntu下面的安装
查看>>
Python 3语法小记(九) 异常 Exception
查看>>
使用shared memory 计算矩阵乘法 (其实并没有加速多少)
查看>>
Django 相关
查看>>
ArcGIS自定义工具箱-字段合并
查看>>
git init
查看>>
训练记录
查看>>
IList和DataSet性能差别 转自 http://blog.csdn.net/ilovemsdn/article/details/2954335
查看>>
Python中的join()函数的用法
查看>>
Hive教程(1)
查看>>
Java集合框架学习
查看>>
第16周总结
查看>>
将Cent0S 7的网卡名称eno33改为eth0
查看>>
透明度Opacity多浏览器兼容处理
查看>>
oracle 常用简单命令语句
查看>>