Strings in the Pocket(马拉车+字符串判断)

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6012
BaoBao has just found two strings s and in his left pocket, where indicates the -th character in string , and indicates the -th character in string .

As BaoBao is bored, he decides to select a substring of and reverse it. Formally speaking, he can select two integers and such that and change the string to .

In how many ways can BaoBao change to using the above operation exactly once? Let be an operation which reverses the substring , and be an operation which reverses the substring . These two operations are considered different, if or .

Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains a string (), while the second line contains another string (). Both strings are composed of lower-cased English letters.

It‘s guaranteed that the sum of of all test cases will not exceed .

Output
For each test case output one line containing one integer, indicating the answer.

Sample Input
2
abcbcdcbd
abcdcbcbd
abc
abc
Sample Output
3
3
Hint
For the first sample test case, BaoBao can do one of the following three operations: (2, 8), (3, 7) or (4, 6).

For the second sample test case, BaoBao can do one of the following three operations: (1, 1), (2, 2) or (3, 3).

题意就是,a要变成b,可以有多少种逆转做法;

分两种情况,1,如果两个相同,用马拉车求回文串数量就好,开longlong

2.找出不同的点坐标,然后看看这两个点坐标之间是不是逆转后相等,不是输出0,是的话,在往两边找出有多少种做法;

。。不知道为什么错了,换板子

原文地址:https://www.cnblogs.com/wzl19981116/p/10797738.html

时间: 2024-08-30 18:34:59

Strings in the Pocket(马拉车+字符串判断)的相关文章

脚本应用之六:字符串判断&处理函数 【 functions_string1 】

测试系统版本:CentOS 6.4 作用:脚本提供判断和处理字符串的函数,可供其他脚本调用.例如:判断字符串是否都是数字\大小写字母.字符串中字母是否为大\小写以及大小写转换和字符串包含关系判断等. 使用:脚本中调用 "./source functions_string1" 代码专区: #/bin/bash #  LY #  ------------------ #  Copyright 2016.4.14, LingYi ([email protected]) QQ:15199525

java 字符串判断是否为空

/** * 方法描述:字符串判断是否为空 * 创建作者:李兴武 * 创建日期:2017-06-22 19:50:01 * * @param str the str * @return the boolean */ public static Boolean isBlank(String str){ if(str!=null) str = str.replaceAll("\r\n|\n\r|\n|\r|\f|\t", ""); if(str==null) return

使用strings查看二进制文件中的字符串

使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以null或者newline结尾. 对于普通文本文件来说,strings没有任何意义,因为文本文件中的任何内容实际都是可打印的字符串.strings最常用的场合就是列出动态库或者可执行程序等二进制文件中出现的字符串,结合grep即可实现查找. strings的使用方法很简单,strings [文件]即可,

java中字符串判断相等能用不等号吗

在项目中有如下语句:Global.NOT_RESTRICT !=companyGroupInfo.getSex()  也就是"NR" != "NR" 返回true(明明应该返回FALSE呀) 字符串在内存中是在字符串池中,如果字符串池已经存在字符串就直接引用地址即可.为什么此时就不行了.经过代码的一番验证发现,如果不涉及数据库,只是java代码对于字符串常量进行操作.Global.NOT_RESTRICT !=companyGroupInfo.getSex() 这一

由一篇吐槽对String空字符串判断的文章所引发的碎碎念

一.起因 最近有篇关于String空字符串判断的文章火了,老是看到这篇文章,既然如此我也只好认真看了下:程序员晒出一段代码引来无数网友狂喷!网友:你就活该当码农! 我也觉得这段代码写的不怎么的,首先程序的正确性应该没有问题,我只是觉得如果写出的代码跟道上认可的规范有违的话可能会恶心到后面接手的人而不自知,我现在莫名打喷嚏的时候就在想肯定是在之前公司写的代码又被接手的人吐槽了- :) 看上去就是个判断字符串是否为空字符串的方法,首先这类方法应该提取到StringUtil类似的工具类中,而这个pri

读取一个文件,给定一个字符串,判断这个字符串在文件中出现的次数

读取一个文件,给定一个字符串,判断这个字符串在文件中出现的次数,面试笔试经常遇到的问题 public class CountStringTest { public static void main(String[] args) { try { //统计E盘下面test.txt中的q字符出现的次数 System.out.println("E盘下面test.txt中的q字符出现的次数为:"); System.err.println(count("E:\\test.txt"

ZOJ4110 Strings in the Pocket(2019浙江省赛)

给出两个字符串,询问有多少种反转方法可以使字符串1变成字符串2. 如果两个串相同,就用马拉车算法找回文串的数量~ 如果两个串不同,从前往后找第一个不同的位置l,从后往前找第二个不同的位置r,反转l和r,判断是否成功~ 如果不成功,记为0 如果成功,以l和r为起点判断是否能反转,记录次数 #include<bits/stdc++.h> using namespace std; const int maxn=2e6+100; typedef long long ll; char s1[maxn];

关于字符串判断的几个常用属性 以及简单项目实现中数组运用的初步思想 蓝懿教育

Label.numberOfLines 可以控制其内的行数 若=0 只要空间够 可以无数行 若=1 1行 : 若=2 2行:类推 UIbutton 通过代码设置字 和 图片 UIbutton *l1=[UIbuttom alloc]initwithframe:CGrectmake…. [l1 settitle:@“111” for state:UIControlStateNormal];   按键上会显示111 [l1 setimage:[UIimage imagenamed:@“…”] for

Python一些字符串判断和转换

设s是字符串: s.isalnum()      判断所有字符都是数字或者字母 s.isalpha()  判断所有字符都是字母 s.isdigit()  判断所有字符都是数字 s.islower() 判断 所有字符都是小写 s.isupper()  判断所有字符都是大写 s.istitle()  判断所有单词都是首字母大写,像标题 s.isspace()  判断所有字符都是空白字符 s.upper() 所有小写字符转换成大写 s.lower() 所有大写字符转换成小写 s.capitalize(