Substring Reverse

Problem

Two strings s and t of the same length are given. Determine whether it is possible to make t from s using exactly one reverse of some its substring.

Input

The first line contains the string s, and the second — the string t. Both strings have the same length from 1 to 200000 characters and consist of lowercase Latin letters.

Output

Output «YES», if it is possible to reverse some substring of s to make s equal to t, and «NO», otherwise.

Examples

Input

abcdefg
abedcfg

Output

YES

Input

abcdefg
abdecfg

Output

NO

题意: 给定两个字符串s、t,能不能反转(逆序)s其中一部分子串使得和t是相同的字符串。

解析:只需要找到需要比较的区间L,R,在这个区间内比较一下是否为相反的子串,就可以了。

// By Mercury_Lc
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[200005];
char t[200005];
while(~scanf("%s %s",&s,&t))
{
int n = strlen(s);
int l = 0, r = n;
for(int i = 0; i < n; i ++)
{
if(s[i] == t[i]) l++;
else break;
}
for(int i = n; i >= 0; i --)
{
if(s[i]== t[i]) r --;
else break;
}
//cout << l << " " << r << endl;
int f = 0;
for(int i = l; i <= r; i ++)
{
if(s[i] != t[r + l - i])
{
f= 1;
break;
}
}
if(f==0)printf("YES\n");
else printf("NO\n");
}
return 0;
}

E.Substring Reverse Gym - 101755E的更多相关文章

  1. [CF1234F] Yet Another Substring Reverse - 字符串,状压DP

    CF1234F Yet Another Substring Reverse Description 给定一个字符串,可以任意翻转一个子串,求最终满足所有字符互不相同的子串的最大长度. 数据范围: \( ...

  2. codeforces#1234F. Yet Another Substring Reverse(子集dp)

    题目链接: https://codeforces.com/contest/1234/problem/F 题意: 给出一个只包含前20个小写字母的字符串,一次操作可以让一段字符颠倒顺序 最多一次这样的操 ...

  3. [codeforces1234F]Yet Another Substring Reverse

    题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长.只能翻转一次或零次. 设一个子串的状态为包含字符的二进制.如子串为$abacd$,则状态为$00000000000000 ...

  4. Codeforces1234F. Yet Another Substring Reverse(状压dp)

    题目链接:传送门 思路: 由于只能翻转一次子串,就相当于找出两个不连续的子串,把在后面的一个子串翻转过来,和第一个子串拼接. 因为题目仅要求子串中的字符不重复,所以字符的先后顺序无关,翻转的操作就相当 ...

  5. sqlserver 巧用REVERSE和SUBSTRING实现lastindexof

    原文:sqlserver 巧用REVERSE和SUBSTRING实现lastindexof select REVERSE(SUBSTRING(REVERSE(testFixtureNumber),0, ...

  6. SQL变量、Substring、charindex、case函数、去除重复

      isnull(aa,0)删除表数据: truncate table aaa 添加字段: ALTER TABLE table1 ADD col1 varchar(200) DEFAULT '2008 ...

  7. SQL中的charindex函数与reverse函数用法

       ----------------------首先介绍charindex函数-----------------------------                                ...

  8. [LeetCode] Palindrome Linked List 回文链表

    Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...

  9. SQL 去掉某字段括号中的值

    今天在数据库匹配数据的时候,发现一些数据存在别名,导致我的数据匹配不上.在这里记录分享一下 例如: 李钟硕 (Lee Jong Suk),这里我匹配的是 “李钟硕” 示例1: SELECT rever ...

随机推荐

  1. 【原创】大叔经验分享(87)marathon重启应用过程服务不可用

    marathon提供多种健康检查方式 常用的有TCP和HTTP, TCP检查端口是否存在,存在则认为实例健康: HTTP检查指定URL的HTTP返回码,返回码正常(2xx.3xx)则认为实例健康: 这 ...

  2. @PostConstruct注解原理解析

    所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 正文 @PostConstruct注解使用简介 在了解一个东西的原理之前,我们得初步的懂得如何 ...

  3. leetcode-29.两数相除(不用乘除法和mod)

    如题,不用乘除法和mod实现两数相除. 这里引用一位clever boy 的解法. class Solution { public: int divide(int dividend, int divi ...

  4. storedownloadd占用cpu高

    禁用App Store的自动更新 

  5. 11 Windows编程——定时器

    周期性的发送WWL_TIMER消息的一个东西,这个周期可以由程序员自己设定.设定周期的数是SetTimer,停止定时器消息发送的函数是:Killximer: 定时器消息的特点: 1.不准确(也就是说, ...

  6. 【Flask+Redis】 python学习第一章 - 7.0 断言 数据库测试 redis学习

    assert 断言 def div(num1, num2): # 断言 assert isinstance(num1, int), "值类型错误" assert isinstanc ...

  7. (17)for循环

    # 把容器里数据拿出来的这个过程 可以叫遍历 迭代 循环 listvar = [1, 2, 3, 4, 5] print(len(listvar)) # 算出列表里面所有元素的个数,len是计算长度 ...

  8. Centos 升级至 OpenSSH 8 rpm包制作

    背景 安全部门扫描系统漏洞,OpenSSH 7.9出现漏洞,需升级到8. 使用 rpmbuild 将源码包编译为 rpm包. yum install rpm-build zlib-devel open ...

  9. PAT Basic 1080 MOOC期终成绩 (25 分)

    对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分( ...

  10. IIS搭建ASP站点

    1. 进入控制面板悬着打开或者关闭Windows功能. 2. 手工选择需要的功能进行安装. 3. 打开运行Internet信息服务(IIS)管理工具. 4. 展开左侧栏看到“Default Web S ...