列表

详情


NC25106. [USACO 2006 Ope l]Scrambled Strings

描述

Given a pair of strings, each 80 or fewer characters in length, determine two things:
* The number of non-blank characters in the first string
* Whether the first string can be rearranged to form the second string.
The input strings will contain only letters (potentially both upper and lower case), digits, and spaces. 'Rearrangement' means strict reordering; no character can be changed, deleted, or added.

输入描述

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)

上一题