Palindromic Game Problem Code: PALINGAM

There are two players A, B playing a game. Player A has a string s with him, and player B has string t with him. Both s and t consist only of lower case English letters and are of equal length. A makes the first move, then B, then A, and so on alternatively. Before the start of the game, the players know the content of both the strings s and t.

These players are building one other string w during the game. Initially, the string w is empty. In each move, a player removes any one character from their respective string and adds this character anywhere (at any position) in the string w. If at any stage of the game, the string w is of length greater than 1 and is a palindrome, then the player who made the last move wins.

If even after the game finishes (ie. when both s and t have become empty strings), no one is able to make the string w a palindrome, then player B wins.

Given the strings s, and t, find out which of A, B will win the game, if both play optimally.

Input

  • The first line of the input contains an integer T, corresponding to the number of test cases. The description of each testcase follows.
  • The first line of each testcase will contain the string s.
  • The second line of each testcase will contain the string t.

Output

For each test case, output "A" or "B" (without quotes) corresponding to the situation, in a new line.

Constraints

  • Subtask 1 (20 points) : 1 ≤ T ≤ 500, All characters of string s are equal, All characters of string t are equal. 1 ≤ |s| = |t| ≤ 500
  • Subtask 2 (80 points) : 1 ≤ T ≤ 500, 1 ≤ |s| = |t| ≤ 500

Example

Input:
3
ab
ab
aba
cde
ab
cd
Output:
B
A
B

Explanation

Testcase 1: If A adds 'a' to w in the first move, B can add 'a' and make the string w = "aa",

which is a palindrome,and hence win. S

imilarly, you can show that no matter what A plays, B can win.Hence the answer is B.

Testcase 2: Player A moves with 'a', player B can put any of the character 'c', 'd' or 'e', Now Player A can create a palindrome by adding 'a'.

Testcase 3: None of the players will be able to make a palindrome of length > 1. So B will win.

—————————————————————————————————————————————

这道题就是有两个人A和B 他们每个人有一个串

(A先起手)每次一个人人能拿出自己串中剩余的字母中的一个加入现有串C的左边或者右边

当C变成一个回文串的时候游戏结束 使这个串变成回文串的一方胜利

我们考虑A起手 如果他下了一个B有的字母 那么无疑B会胜利

如果他下了一个B没有的字母 且这个字母他有两个 那么他一定胜利

不然 如果B下的这个字母A有那么A会胜利 不然不论如何下这个串都不会成为回文串

那么平局下 按提议B会胜利

codechef AUG17 T4 Palindromic Game的更多相关文章

  1. codechef AUG17 T2 Chef and Mover

    Chef and Mover Problem Code: CHEFMOVR Chef's dog Snuffles has so many things to play with! This time ...

  2. codechef AUG17 T1 Chef and Rainbow Array

    Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some array ...

  3. codechef AUG17 T5 Chef And Fibonacci Array

    Chef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i ...

  4. codechef AUG17 T3 Greedy Candidates

    Greedy Candidates Problem Code: GCAC The placements/recruitment season is going on in various colleg ...

  5. codechef T4 IPC Trainers

    IPCTRAIN: 训练营教练题目描述 本次印度编程训练营(Indian Programming Camp,IPC)共请到了 N 名教练.训练营的日 程安排有 M 天,每天最多上一节课.第 i 名教练 ...

  6. codechef MAY18 div2 部分题解

    T1 https://www.codechef.com/MAY18B/problems/RD19 刚开始zz了,其实很简单. 删除一个数不会使gcd变小,于是就只有0/1两种情况 T2 https:/ ...

  7. [Codechef - AASHRAM] Gaithonde Leaves Aashram - 线段树,DFS序

    [Codechef - AASHRAM] Gaithonde Leaves Aashram Description 给出一棵树,树的"N"节点根植于节点1,每个节点'u'与权重a[ ...

  8. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  9. 使用T4模板生成不同部署环境下的配置文件

    在开发企业级应用的时候,通常会有不同的开发环境,比如有开发环境,测试环境,正式环境,生产环境等.在一份代码部署到不同环境的时候,不同环境的配置文件可能需要根据目标环境不同而不同.比如在开发环境中,数据 ...

随机推荐

  1. http请求中客户端真实的ip

    private String getRemoteAddr() { String ip = ""; String unknow = "unknown"; try ...

  2. 项目10.2-企业级自动化运维工具---puppet详解

    1.认识puppet 1.1 引入 puppet是什么,咱们先不用专业的名词解释它,咱们先描述一些工作场景,看明白这些工作场景,自然会知道puppet是什么. (1)场景一: 管理员想要在100台服务 ...

  3. 深入解析AJAX的原理

    AJAX:Asynchronous JavaScript And Xml(异步的JS和XML) 同步:客户端发起请求>服务端的处理和响应>客户端重新载入页面(循环) 异步:客户端实时请求& ...

  4. 免费证书Let’s Encrypt

    我们自己也可以签发 SSL 安全证书,但是我们自己签发的安全证书不会被主流的浏览器信任,所以我们需要被信任的证书授权中心( CA )签发的安全证书.而一般的 SSL 安全证书签发服务都比较贵,比如 G ...

  5. 802. Find Eventual Safe States

    https://leetcode.com/problems/find-eventual-safe-states/description/ class Solution { public: vector ...

  6. hihocoder1015 kmp算法

    #1015 : KMP算法 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在 ...

  7. [译]Exactly once is NOT exactly the same

    近日学习Pulsar文档时,注意到Pulsar提到其提供的是effectively-once语义,而不是其它流计算引擎announce的exactly-once语义,并引用了Exactly once ...

  8. lambda表达式与函数接口的关系以及使用案例

    lambda表达式与函数式接口是结合使用的. 函数式接口:接口中只有一个抽象方法的接口,其中可以包括default修饰,static 修饰的实例方法.函数式接口可以在接口上添加@FuncationIn ...

  9. 设计模式学习笔记——java中常用的设计模式

    单例设计模式(Singleton Pattern) 观察者模式(Observer Pattern) 工厂模式(Factory Pattern) 策略模式(Strategy Pattern) 适配器模式 ...

  10. 如何选择Android自动化框架的几点拙见

    首先由于我自己也是个新手,也是在学习各种框架然后给公司项目选定相应自动化框架,研究移动自动化测试框架也就近段时间而已,所以我只能从我自己今天为止的认知角度给各个框架抒发我自己的拙见,你看是否能从中接纳 ...