#K12526. Rearrange and Compare
Rearrange and Compare
Rearrange and Compare
You are given two strings s1
and s2
. Your task is to determine whether the characters of s1
can be rearranged to exactly form s2
. The comparison is case-sensitive and considers all characters including spaces and punctuation.
If the characters in s1
can be rearranged to match s2
, output Yes
. Otherwise, output No
.
For example, if s1 = "listen"
and s2 = "silent"
, the output should be Yes
because the letters can be rearranged to match. However, for s1 = "apple"
and s2 = "pleaple"
, the output is No
because the character counts do not match.
Note: Inputs are to be read from standard input (stdin) and output should be printed to standard output (stdout).
inputFormat
The input consists of exactly two lines:
- The first line contains the string
s1
. - The second line contains the string
s2
.
Both strings may contain spaces, uppercase and lowercase letters, digits, and punctuation.
outputFormat
Output a single line containing either Yes
if the characters of s1
can be rearranged to match s2
, or No
otherwise.
listen
silent
Yes