牛客华为机试HJ81
作者:互联网
1. 问题描述
2. Solution
1、思路分析
用数组充当自定义哈希表来统计字符串中字符出现次数,若存在一个字符在短字符串中出现过,而未在长字符串中出现则返回False。
2、代码实现
import sys
if sys.platform != "linux":
sys.stdin = open("input/HJ81.txt")
def count_str(s):
cnt = [False] * 26
for c in s:
cnt[ord(c) - ord('a')] = True
return cnt
def solve(s, l):
s_cnt = count_str(s)
l_cnt = count_str(l)
for i in range(26):
if s_cnt[i] and not l_cnt[i]:
return False
return True
while True:
try:
short_letters = input().strip()
long_letters = input().strip()
if solve(short_letters, long_letters):
print("true")
else:
print("false")
except:
break
标签:cnt,letters,return,sys,牛客,input,机试,True,HJ81 来源: https://www.cnblogs.com/junstat/p/16177293.html