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 ...
随机推荐
- Task执行多次
项目中,曾经出现过启动时数据库连接数瞬间增大,当时并没有注意该问题. 后期,由于Task任务多次执行,才着手查看这个问题,经排查,由于tomcat中webapp配置多次,导致webapp被扫描多次(配 ...
- 洛谷 P1047 校门外的树(待完善)
链接:https://www.luogu.org/problemnew/show/P1047 题目: 题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是11米.我们可以把马路看 ...
- [C#] LINQ之SelectMany和GroupJoin
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 冒泡(bubblesort)、选择排序、插入排序、快速排序
冒泡排序(bubblesort) 特点:通过换位置的方式,一直向上冒泡 package main import "fmt" func bubbleSortAsc(arrayA [] ...
- 括号配对检测 A
括号配对检测 A ...
- 操作RDS文档说明
操作RDS文档,让你对阿里云的知识更加了解.
- Xcode8 1 创建coreData的ManagedObject后,报错 linker command failed with exit code 1
Xcode8 1 创建coreData的ManagedObject后,报错 使用Xcode 8.1 创建coreData的ManagedObject后,报错. duplicate symbol OBJ ...
- Sqlmap对dvwa进行sql注入测试
前提准备条件: 1.下载安装dvwa,下载链接地址:http://www.dvwa.co.uk/.2.需要安装python运行环境.3.下载sqlmap包并将其解压. 一.查看所有的数据库;(其中db ...
- PHP获取当前页面地址
#测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."< ...
- 【JavaWeb】通过邮件找回密码
前言 本文将介绍忘记密码时通过发送重置密码邮件找回密码的实现思路.整个实现过程中最重要的就是以下三点: 如何发送邮件到用户指定邮箱 邮件中的重置密码链接构成是怎么样的 验证重置密码链接的合法性(是否过 ...