NC25003. [USACO 2008 Ope S]Word Power
描述
输入描述
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 contains a string that is the name of the ith cow
* Lines N+2..N+M+1: Line N+i+1 contains the ith good string
输出描述
* Lines 1..N+1: Line i+1 contains the number of quality points of the ith name
示例1
输入:
5 3 Bessie Jonathan Montgomery Alicia Angola se nGo Ont
输出:
1 1 2 0 1
说明:
There are 5 cows, and their names are "Bessie", "Jonathan", "Montgomery", "Alicia", and "Angola". The 3 good strings are "se", "nGo", and "Ont".Python3 解法, 执行用时: 2001ms, 内存消耗: 0K, 提交时间: 2023-08-18 17:40:34
n, m = map(int, input().split()) arr = [] for i in range(n+m): arr.append(input().upper()) s = arr[n:] arr = arr[:n] def issubseq(s, t): n, m = len(s), len(t) i = j = 0 while i < n and j < m: if s[i] == t[j]: i += 1 j += 1 return i == n r = [0 for i in range(n)] for i, cow in enumerate(arr): for t in s: if issubseq(t, cow): r[i] += 1 for c in r: print(c)