F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

A and B Problem

Time 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
3 AABB ABAB AABABA
 

Sample Output
Case 1: 0 Case 2: 1 Case 3: 1
 

Author
iSea@WHU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 12:55:18, Gzip enabled