首页 > 其他分享 >XI Samara Regional Intercollegiate Programming Contest Problem E. Substring Reverse

XI Samara Regional Intercollegiate Programming Contest Problem E. Substring Reverse

时间:2023-04-24 23:36:59浏览次数:40  
标签:XI Reverse int ll long Substring include pos2 define

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
standard input standard output
abcdefg
abedcfg
YES
abcdefg
abdecfg
NO

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 500005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-7
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    a = a % mod;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

bool prime(int x) {
    if (x == 0 || x == 1)return false;
    for (int i = 2; i <= sqrt(x); i++) {
        if (x%i == 0)return false;
    }
    return true;
}


int main()
{
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int i, j;
    int len = s.length();
    int pos1, pos2;
    if (s == t) {
        int flag = 0;
        cout << "YES" << endl;
    }
    else {
        for (i = 0; i < len; i++) {
            if (s[i] != t[i]) {
                pos1 = i;
                break;
            }
        }
        for (i = len - 1; i >= 0; i--) {
            if (s[i] != t[i]) {
                pos2 = i;
                break;
            }
        }
        int pp1 = pos1, pp2 = pos2;
        int  flag = 0;
        while (1) {
            if (s[pos1] != t[pos2]) {
                flag = 1;
                break;
            }
            pos1++;
            pos2--;
            if (pos1 > pp2)break;
        }
        if (flag)cout << "NO" << endl;
        else cout << "YES" << endl;
    }
}

标签:XI,Reverse,int,ll,long,Substring,include,pos2,define
From: https://blog.51cto.com/u_15657999/6221993

相关文章

  • XI Samara Regional Intercollegiate Programming Contest Problem L. Queries on a
    Astringsisgiven.Alsothereisastringp,andinitiallyitisempty.Youneedtoperformqoperationsofkind«addalettertotheendofthestringp»and«removealetterfromtheendofthestringp»,andafterperformingeachoperationyoumu......
  • XI Samara Regional Intercollegiate Programming Contest Problem K. Video Reviews
    Thestudio«LodkaGaming»isengagedinadvertisingoftheirnewgame«.C.O.N.T.E.S.T:UnexpectedBehaviour».Thestudio’smarketerisplanningtocommunicatewithnvideobloggersonebyone(inthepredeterminedorder,startingfromthe1-standend......
  • axios传递参数的使用
    今天在学习elasticsearch时,遇到一个问题:项目中前端采用的是Vue2+axios,后端的接口采用Restful风格来接收:关于Resultful风格:1.GET(SELECT):从服务器取出资源(一项或多项);2.POST(CREATE):在服务器新建一个资源;3.PUT(UPDATE):在服务器更新资源(客户端提供改变后的完整资源);......
  • XI Samara Regional Intercollegiate Programming Contest Problem C. Third-Party
    Pavelisdevelopingagame.Todothat,heneedsfunctionsavailableinathird-partylibrarytoofamoustobecalled.Itisknownthatthefunctionifirstappearedinversionaiandexisteduntilversionbi,andstartingfromtheversionbi+1,it......
  • XI Samara Regional Intercollegiate Programming Contest Problem B. Minimal Are
    Youaregivenastrictlyconvexpolygon.Findtheminimalpossibleareaofnon-degeneratetrianglewhoseverticesaretheverticesofthepolygon.InputThefirstlinecontainsasingleintegern(3≤n≤200000)—thenumberofpolygonvertices.Eac......
  • [C#]中String、String[]、List<string>相互转换及string成员substring、split简单使用
    一、相互转换1.String>String[]Strings="a,b,c,d,e";String[]sArray=s.Split(',');2.String[]>Stringstring[]sArray={"a","b","c","d","e"};strings=String.Join(",......
  • Numerical Approximation Chapter 6 Notes
    Weierstrasstheoremapproximation之间也有高低,所以我们在compactsubset里面会有bestapproximation.但是以polynomialinterpolation为例,随着不断选更多的Chebyshevinterpolationpoints,对应的插值多项式次数越来越高的同时也会在插值点以外的地方越来越靠近函数本身。这种情......
  • ai问答:使用 Vue3 组合式API 和 TS 配置 axios 拦截器 http错误状态
    通过axios.create()可以创建一个axios实例axiosInstance,参数如下:baseURL:请求前缀timeout:超时时间headers:请求头默认配置:import{defineComponent}from'vue'importaxiosfrom'axios'exportdefaultdefineComponent({setup(){//实例-默认配置......
  • AXI DMA 设计分析
    AXIDMA架构SBIUSBIU:SlaveBusInterfaceUnit。从机总线接口模块:通过外部AHB/APB4主机访问DW_axi_dmac的内部寄存器的读写控制逻辑。从机总线接口可以通过DMAX_SLVIF_MODE参数进行配置。DMAX_SLVIF_MODE:用于从机接口的协议。AHB(0),APB4(2)根据子系统要求,可以选择......
  • substring截取使用
    privatefinalstaticintentNameLength=32;publicstaticvoidmain(String[]args){Stringentname="王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王王......