#C3150. Exactly One Swap Transformation
Exactly One Swap Transformation
Exactly One Swap Transformation
Louisa loves word puzzles! Given two strings source and target, determine whether the target word can be obtained by performing exactly one swap of two letters in the source word. A swap means choosing two distinct positions in the source string and exchanging their characters. If the transformation is possible by doing exactly one swap, output YES
. Otherwise, output NO
.
Note: The strings must be of equal length for a swap to be considered. If they differ in length or the number of mismatches is not exactly 2, the answer is NO
.
For example:
- Input:
converse
andconserve
→ Output:YES
- Input:
listen
andsilent
→ Output:NO
inputFormat
The input is given via standard input (stdin) with two lines:
- The first line contains the
source
string. - The second line contains the
target
string.
outputFormat
Output a single line to standard output (stdout) with either YES
if the target can be obtained by exactly one swap from the source, or NO
otherwise.
listen
silent
NO