//
Feel when thinking faster but a waste of time when the idea of code implementation
And when there was a clear bare code and do not react quickly with other methods
//
Here is the code plus problem solution
Focusing on two questions have not had gf
AAK distance | ||
|
Problem Description
Students always want to AK.
So what the boss gives a string composed of uppercase letters, he wants to help you figure out where the most distant pair of 'A' and 'K'.
For example the following string:
BKABGKWAXKA
farthest one pair of 'A' and 'K' pitch of 6, a spacer 6 therebetween characters.
Input Format
Line, a character string constituted by the capital letter
Output Format
An integer K and A represents the farthest distance. A K required to be on the left, and if not, outputs -1
Sample input 1
BKABGKWAXKA
Sample output 1
6
Sample input 2
KKKKKKKKKKAAAAAAAAAAAAAAA
Sample output 2
-1
prompt
A length <= string <= 10000
Music box B Diminshing | ||
|
Problem Description
What the boss Diminshing playing a music game, the game is simple, what the boss is still enthusiastic.
The game begins with a side length n 1 is a block height of a folded n columns.
There are red and blue squares.
Gameplay: The player selects two adjacent and different-colored squares, to eliminate them. Then the box above will automatically fall, making the rest of the block remains cylindrical.
Players can be any time of the operation, the more the elimination of the box, the higher the score. What the boss wants to know: How much eliminated up to the box?
Input Format
A string composed of 0 and 1, a block diagram of the column when the game starts. Where 0 represents a blue square, 1 red square.
Output Format
An integer representing the number of squares up to be eliminated.
Sample input 1
0011
Sample output 1
4
Sample input 2
11011010001011
Sample output 2
12
Sample input 3
0
Sample output 3
0
prompt
Provided the string length n