#K81882. Minimizing Cow Turns
Minimizing Cow Turns
Minimizing Cow Turns
You are given a string S consisting solely of the characters L
and R
. Each character stands for the direction a cow is facing: L
means left and R
means right. Your task is to determine the minimum number of cows that must be instructed to turn around so that all cows face the same direction.
In mathematical terms, if we denote the number of cows facing left by \(n_L\) and the number of cows facing right by \(n_R\), then the answer is:
[ \min(n_L, n_R) ]
Note: The input for each test case is read from standard input (stdin
) and the output should be written to standard output (stdout
).
inputFormat
The input consists of a single line containing a non-empty string S
of characters. Each character is either L
or R
, representing the initial orientation of a cow.
Example:
LRLR
outputFormat
Output a single integer representing the minimum number of cows that need to be turned so that all cows face the same direction.
Example:
2## sample
LLLL
0
</p>