码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-04-30 19:52:08      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:hat   tip   sel   之间   sub   回文串   follow   lower   har   

题目: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,是的话,在往两边找出有多少种做法;

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

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

标签:hat   tip   sel   之间   sub   回文串   follow   lower   har   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!