Gym 100989E 字符串
Description
Islam is usually in a hurry. He often types his passwords incorrectly. He hates retyping his password several times whenever he tries to login, especially that his passwords are usually very long. He believes that websites should be tolerant with very long passwords. In other words, he believes that if a password is very long, and there is only one mistake in the password, the website should allow the user to login.
Your task is to check if an entered password should be accepted according to Islam, or not. The entered password will be accepted if it matches the user’s password, or if the user’s password length is at least 8 characters and the user made a mistake with only one character (either replaced it with a wrong character or dropped it).
Given the user’s password, and the entered password, determine if the entered password should be accepted according to Islam.
Input
The first line of input contains the user’s password.
The second line of input contains the entered password.
Both strings contain only lowercase and uppercase English letters.
The length of each string is at least 1 and at most 100.
Output
Print yes if the entered password should be accepted according to Islam, otherwise print no.
Sample Input
AgentMahone
IslamIsMahone
no
ofmahone
ofmahome
yes
algorithms
algorthms
yes
Mahone
mahonE
no 题意: 题解:给两个串a,b; a的长度len1 b的长度len2 a长度小于8的直接判断,长度大于等于8的 根据题意
两个串的长度只存在 len1==len2或者 len1-len2=1两种情况才可能yes,分别特判一下就可以了。
len1==len2情况下 只能是两个串相同或者某一个字母被替换,遍历一遍验证
len1-len2==1 情况下 只能是丢失一个字母 遍历一遍 当遇到字母不同时,b串向后移动一位继续遍历
当只出现一次对应字母不同时,才能说明只丢失了一个字母
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[];
char b[];
int main()
{
scanf("%s",a);
scanf("%s",b);
int len1=strlen(a);
int len2=strlen(b);
if(len1<)
{
if(strcmp(a,b)==)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
else
{
if(len2>len1)
{
cout<<"no"<<endl;
return ;
}
if(strcmp(a,b)==)
{
cout<<"yes"<<endl;
return ;
}
int flag=;
if(len1==len2)
{
for(int i=;i<len1;i++)
{
if(a[i]!=b[i])
{
flag++;
}
}
if(flag==)
{
cout<<"yes"<<endl;
return ;
}
else
{
cout<<"no"<<endl;
return ;
}
}
if(len1-len2==)
{
for(int i=;i<len1;i++)
{
if(a[i]!=b[i])
{
for(int j=len2-;j>=i;j--)
{
b[j+]=b[j];
}
b[i]=' ';
flag++;
}
}
if(flag==)
{
cout<<"yes"<<endl;
return ;
}
else
{
cout<<"no"<<endl;
return ;
}
}
cout<<"no"<<endl;
}
return ;
}
Gym 100989E 字符串的更多相关文章
- D - Counting Test Gym - 101532D 字符串
Yousef has a string s that is used to build a magical string w by repeating the string s infinitely ...
- Gym - 100989E
Islam is usually in a hurry. He often types his passwords incorrectly. He hates retyping his passwor ...
- UESTC 2016 Summer Training #1 Div.2
最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】
C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...
- Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】
A. Who is the winner? time limit per test:1 second memory limit per test:64 megabytes input:standard ...
- Codeforces Gym 100338B Spam Filter 字符串哈希+贝叶斯公式
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- 强化学习实战 | 自定义gym环境之显示字符串
如果想用强化学习去实现扫雷.2048这种带有数字提示信息的游戏,自然是希望自定义 gym 环境时能把字符显示出来.上网查了很久,没有找到gym自带的图形工具Viewer可以显示字符串的信息,反而是通过 ...
- codeforces gym 100286 I iSharp (字符串模拟)
题目链接 给定一个字符串.输入是int& a*[]&, b, c*; 输出是 int&&[]* a;int& b;int&* c; 输入格式里逗号后面一 ...
随机推荐
- Bootstrap HTML编码规范
语法 1.用两个空格来代替制表符(Tab)--这是唯一能保证在所有的环境下获得一致展现的方法. 2.嵌套元素应当缩进一次(即两个空格). 3.对于属性的定义,属性值确保全部都用双引(避免使用单引号). ...
- DOM4j-中文API
1.DOM4J简介 DOM4J是 dom4j.org 出品的一个开源 XML 解析包.DOM4J应用于 Java 平台,采用了 Java 集合框架并完全支持 DOM,SAX 和 JAXP. ...
- 手写promise
写在前面: 在目前的前端分开中,我们对于异步方法的使用越来越频繁,那么如果处理异步方法的返回结果,如果优雅的进行异步处理对于一个合格的前端开发者而言就显得尤为重要,其中在面试中被问道最多的就是对Pro ...
- Java - Java 中的三种 ClassLoader
1.虚拟机类加载器(称为“bootstrap class loader”),它本身没有父类加载器,它负责加载虚拟机的内置类,由于它是用C.C++写的,所以Java无法拿到其class文件,返回的都是空 ...
- Android 性能篇 -- 带你领略Android内存泄漏的前世今生
基础了解 什么是内存泄漏? 内存泄漏是当程序不再使用到的内存时,释放内存失败而产生了无用的内存消耗.内存泄漏并不是指物理上的内存消失,这里的内存泄漏是指由程序分配的内存但是由于程序逻辑错误而导致程序失 ...
- nuxt.js express模板项目服务器部署
nuxt版本:0.10.6 技术栈:nuxt.js, express, pm2 部署环境:windows server 之前用nuxt.js 的express的模板项目在windows下用nginx进 ...
- h5获取摄像头拍照功能
完整代码展示 <!DOCTYPE html> <head> <title>HTML5 GetUserMedia Demo</title> <met ...
- python变量声明及简单数据类型
一.python声明变量 变量的命名和使用 # 在Python中使用变量时,需要遵守一些规则和指南. # 违反这些规则将引发错误,而指南旨在让你编写的代码更容易阅读和理解.请务必牢记下述有关变量的规则 ...
- Hyper-V动态迁移中?小心性能损失
动态迁移是虚拟化技术的一个标志,它允许虚拟机在服务器间进行动态迁移.调节负载平衡.性能管理.备灾管理和数据中心维护.Windows Server 2012 R2中的Hyper-V动态迁移默认功能具备相 ...
- iOS下单例模式实现(二)利用宏定义快速实现
在上一节里提到了用利用gcd快速实现单例模式. 一个项目里面可能有好几个类都需要实现单例模式.为了更高效的编码,可以利用c语言中宏定义来实现. 新建一个Singleton.h的头文件. // @int ...