E.Substring Reverse Gym - 101755E
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的更多相关文章
- [CF1234F] Yet Another Substring Reverse - 字符串,状压DP
CF1234F Yet Another Substring Reverse Description 给定一个字符串,可以任意翻转一个子串,求最终满足所有字符互不相同的子串的最大长度. 数据范围: \( ...
- codeforces#1234F. Yet Another Substring Reverse(子集dp)
题目链接: https://codeforces.com/contest/1234/problem/F 题意: 给出一个只包含前20个小写字母的字符串,一次操作可以让一段字符颠倒顺序 最多一次这样的操 ...
- [codeforces1234F]Yet Another Substring Reverse
题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长.只能翻转一次或零次. 设一个子串的状态为包含字符的二进制.如子串为$abacd$,则状态为$00000000000000 ...
- Codeforces1234F. Yet Another Substring Reverse(状压dp)
题目链接:传送门 思路: 由于只能翻转一次子串,就相当于找出两个不连续的子串,把在后面的一个子串翻转过来,和第一个子串拼接. 因为题目仅要求子串中的字符不重复,所以字符的先后顺序无关,翻转的操作就相当 ...
- sqlserver 巧用REVERSE和SUBSTRING实现lastindexof
原文:sqlserver 巧用REVERSE和SUBSTRING实现lastindexof select REVERSE(SUBSTRING(REVERSE(testFixtureNumber),0, ...
- SQL变量、Substring、charindex、case函数、去除重复
isnull(aa,0)删除表数据: truncate table aaa 添加字段: ALTER TABLE table1 ADD col1 varchar(200) DEFAULT '2008 ...
- SQL中的charindex函数与reverse函数用法
----------------------首先介绍charindex函数----------------------------- ...
- [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 ...
- SQL 去掉某字段括号中的值
今天在数据库匹配数据的时候,发现一些数据存在别名,导致我的数据匹配不上.在这里记录分享一下 例如: 李钟硕 (Lee Jong Suk),这里我匹配的是 “李钟硕” 示例1: SELECT rever ...
随机推荐
- hadoop2.7.7 分布式集群安装与配置
环境准备 服务器四台: 系统信息 角色 hostname IP地址 Centos7.4 Mster hadoop-master-001 10.0.15.100 Centos7.4 Slave hado ...
- MyCat 插件 的应用
什么是MyCat MyCAT是一款由阿里Cobar演变而来的用于支持数据库,读写分离.分表分库的分布式中间件.MyCAT支持Oracle.MSSQL.MYSQL.PG.DB2关系型数据库,同时也支持M ...
- python 练习:函数1
习题: 定义一个方法 func,该func可以引入任意多的整型参数,结果返回其中最大与最小的值. def func(**args): return max(args),min(args) 定义一个方法 ...
- vue 集成jTopo 处理方法
jTopo 帮助说明网站 http://www.jtopo.com/index.html 使用例子: http://www.jtopo.com/demo/helloworld.html 不建议直接安装 ...
- XXX银行人事管理系统-数据库设计
1. 用户.权限.角色关系用户基本信息 userinfo [人员表]权限表actions[权限表]员工类型表usertype [管理组表]权限映射表actionmapping [权限映射表]权限分栏表 ...
- Java Web-JSTL
Java Web-JSTL 概念 Java Server Pages Tag Library:JSP标准标签库 是由Apache组织提供的开源.免费JSP标签 用于简化和替换JSP页面上的Java代码 ...
- 使用shared memory 计算矩阵乘法 (其实并没有加速多少)
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include "d ...
- php文件包含漏洞 file inclusion vulnerability
0x00 何为文件包含漏洞 开发人员如果在写类似include "a.php"的代码时,如果将a.php写成了可变的值,那么就可以在上面做文章,举个理想的例子: <? inc ...
- Missing Push Notification Entitlement解决方法
原委 最近提交APP到Apple Store审核,结果很快就收到Apple很"贴心"的邮件.原文如下: Dear developer, We have discovered one ...
- leetcode-104.二叉树最大深度 · BTree + 递归
easy 题就不详细叙述题面和样例了,见谅. 题面 统计二叉树的最大深度. 算法 递归搜索二叉树,返回左右子树的最大深度. 源码 class Solution { public: int maxDep ...