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; 输入格式里逗号后面一 ...
随机推荐
- python内置函数map/reduce/filter
python有几个内置的函数很有意 思:map/filter/reduce,都是对一个集合进行处理,filter很容易理解用于过滤,map用于映射,reduce用于归并. 是python列表方法的三架 ...
- js浮点数加减乘除
浮点数精确计算 /** ** 加法函数,用来得到精确的加法结果 ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显.这个函数返回较为精确的加法结果. ** 调用:ac ...
- ECMAScript 6入门扩展笔记
字符串扩展 Unicode相关补充 引入"\u{xx}"来表示码点,之前只能表示\u0000-\uffff引入String.fromCodePoint()能正确读取大于uFFFF的 ...
- atm-interface-shopping
from db import db_handlerfrom interface import bank def shopping_interface(name, cost, shoppingcart) ...
- nuxt.js服务端缓存lru-cache
对于部分网页进行服务端的缓存,可以获得更好的渲染性能,但是缓存又涉及到一个数据的及时性的问题,所以在及时性和性能之间要有平衡和取舍. 官方文档里面写的使用方法 按照这个配置,试过了没什么用,但是从文档 ...
- JZOJ 4735. 最小圈
Description 对于一张有向图,要你求图中最小圈的平均值最小是多少,即若一个圈经过k个节点,那么一个圈的平均值为圈上k条边权的和除以k,现要求其中的最小值 Input 第一行2个正整数,分别为 ...
- python3调取百度地图API输出某地点的经纬度信息
1. 查看API接口说明 地址:http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding 注:callback ...
- Kali 安装VMtools(最新)
老方法安装的VMtools不能进行主宿切换,下面是kali最新版安装VMtools的方法 一.换国内源&更新源 参考 Kali 2017更新源 二.安装VMtools apt-get inst ...
- day10 消息队列,多进程和多线程以及协程,异步IO,事件驱动等
回顾一下线程和进程 线程与进程的区别 守护线程: 队列: 两种方式: 先进先出 # 后入先出 #卖水果,后来的来的是新的 生产者消费者模型: 生产包子, 吃包子 事件 event: 红绿灯模型 ...
- IOS开发学习笔记012-核心语法
1.点语法 2.成员变量的作用域 3. @property和@synthesize 4.id类型 5.构造方法 6.自定义构造方法 7.模板修改 8.Category - 分类 9.类扩展 一.点语法 ...