#K44262. Minimum Operations to Achieve Preferred Door State
Minimum Operations to Achieve Preferred Door State
Minimum Operations to Achieve Preferred Door State
You are given the current states of two doors and their corresponding preferred states. Each door state is represented by a capital letter: 'O' for Open and 'C' for Closed. In a single operation, you can change the state of a door from 'O' to 'C' or vice versa. Your task is to determine the minimum number of operations required so that both doors match their preferred states.
More formally, given initial states ( initial1 ) and ( initial2 ) and preferred states ( preferred1 ) and ( preferred2 ) for a pair of doors, the answer is the sum of operations needed for each door. For each door, if the initial state does not equal the preferred state, a single operation is needed.
The mathematical formulation is: [ \text{operations} = \mathbf{1}{{initial1 \neq preferred1}} + \mathbf{1}{{initial2 \neq preferred2}} ]
Input will be given via standard input and output should be printed to standard output.
inputFormat
The input consists of a single line containing four space-separated characters. The first two characters represent the initial states of the first and second doors, respectively, and the last two represent their corresponding preferred states. Each character is either 'O' or 'C'.
outputFormat
Output a single integer indicating the minimum number of operations required to convert both doors to their preferred states.## sample
O C O O
1