
Chicken brother is very happy today, because he attained N pieces of biscuits whose tastes are A or B. These biscuits are put into a box. Now, he can only take out one piece of biscuit from the box one time. As we all know, chicken brother is a creative man. He wants to put an A biscuit and a B biscuit together and eat them. If he take out an A biscuit from the box and then he take out a B biscuit continuously, he can put them together and eat happily. Chicken brother’s happiness will plus one when he eat A and B biscuit together one time.
Now, you are given the arrangement of the biscuits in the box(from top to bottom) ,please output the happiness of Chicken Brother when he take out all biscuit from the box.
The first line is an integer indicates the number of test cases.
In each case, there is one line includes a string consists of characters ‘A’ and ‘B’.
The length of string is not more than 1000000.
For each test case:
The first line output “Case #k:", k indicates the case number.
The second line output the answer.
題解:
特别提醒:此題出題人已挖好大坑等着萌新們入坑,我也是第一次遇到這種100W就TL的情況,原因我給你們分析一下,就是這個strlen的應用,之前我将strlen放在for循環内,複雜度為100W*100W,O(n^2)必然逾時,隻要把strlen提出來,複雜度降為100W+100W,O(n+n),神TM知道這個函數調用也會TL!
下面附上AC代碼: