NC25106. [USACO 2006 Ope l]Scrambled Strings
描述
输入描述
Line 1: String 1.
Line 2: String 2.
输出描述
Line 1: The length of the first string
Line 2: A single character: y or n. 'y' means "yes, the first string can be rearranged to form the second". 'n' means otherwise.
示例1
输入:
computers are fun future mac person
输出:
15 y
说明:
The first string has 15 non-blank characters and can be rearranged to form the second string.Python3 解法, 执行用时: 43ms, 内存消耗: 4592K, 提交时间: 2023-08-18 17:21:37
s1 = input().strip('\n') s2 = input().strip('\n') o1 = len(s1.replace(' ', '')) from collections import Counter c1 = Counter(s1) c2 = Counter(s2) flag = 'y' for k, v in c2.items(): if c1[k] < v: flag = 'n' break print(o1) print(flag)