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; 输入格式里逗号后面一 ...
随机推荐
- bootstrap3 文档随看
唉 昨天看的是2,早知道就只可以看3啦,虽然整体不变,但是小改小闹的还是很多啦.产品上线是需要升级的,但是像这么改会很烦哎,有些样式名字修改,用法修改,功能修改,那让用惯了2的人还得把之前记忆清除了然 ...
- Linux下Jenkins与GitHub自动构建NetCore与部署
今天我们来谈谈NetCore在Linux底下的持续集成与部署.NetCore我就不多介绍了,持续集成用的是Jenkins,源代码管理器用的是GitHub.我们就跟着博文往下走吧. 1.Linux环境 ...
- rem适配方案
页面布局单位计算 一般有两大类:绝对长度单位和相对长度单位 绝对长度单位: px 像素:是显示屏上显示的每一个小点,为显示的最小单位 in 英寸,1in = 96px cm 厘米,1cm = 37.8 ...
- 64位系统InlineHook
APIHook64Class.h #ifndef APIHOOK64CLASS_H_ #define APIHOOK64CLASS_H_ #include <Windows.h> clas ...
- 第一篇:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
需求:python如何实现普通用户登录服务器后切换到root用户再执行命令 解决参考: 代码: def verification_ssh(host,username,password,port,roo ...
- 关于mybatis callSettersOnNulls 配置
今天做了一件坑了自己的事情,为此浪费了好多时间... 在mybatis的设置中,看到了这样的一行设置.出于程序员的好奇,去搜索了一下,这条设置是干什么的. <setting name=" ...
- thinkphp 3.2.3 - App.class.php 解析
class App { public static function init() { load_ext_file(COMMON_PATH); // { // /home/www/www.domain ...
- GoF23种设计模式之创建型模式之原型模式
一.概述 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 二.适用性 1.当一个系统应该独立于它的产品创建.构成和表示的时候. 2.当要实例化的类是在运行时刻指定的时候,例如:通过动 ...
- Scrapy用pipelines把字典保存为csv格式
import csv class MyProjectPipeline(object): # 保存为csv格式 def __init__(self): # 打开文件,指定方式为写,利用第3个参数把csv ...
- 动态规划:HDU1789-Doing Homework again
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...