|
||||||||||
A and B ProblemTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1009 Accepted Submission(s): 342 Problem Description After calculating A + B, let¡¯s consider another easy problem which only contains A and B. You are given a string s containing only the letters 'A' and 'B'. The letters are arranged in a circle, so the last and first characters are adjacent. You will perform a series of swaps until all the 'A's form one consecutive sequence and all the 'B's form another consecutive sequence. In each swap, you can select any two characters and swap them. Find the minimal number of swaps necessary to reach your goal. Input The first line contains a single integer T, indicating the number of test cases. Each test case only contains a string as description. Technical Specification 1. 1 <= T <= 100 2. 1 <= |S| <= 100000, |S| indicating the length of the string. Output For each test case, output the case number first, then the minimal number of swaps. Sample Input
Sample Output
Author iSea@WHU Source | ||||||||||
|