zltzlt 发表于 2019-10-25 21:36
A 中只有一个 A,B 中有两个 A
那就拜托说得形象些吧,比如:A 字符串是某物品的标签的库存,其中的某一个物品的标签出现多少次,就代表该物品的数量,B 字符串是预计要从 A 中取出的物品,同样出现次数即数量,判断能否全部成功取出。
这样的感觉。
class CompareString:
def __init__(self):
self.keys =
self.comp_dict = dict.fromkeys(self.keys, 0)
def compare(self, A, B):
for letter in A:
self.comp_dict += 1
for letter in B:
self.comp_dict -= 1
if self.comp_dict < 0:
return False
return True
if __name__ == '__main__':
A = 'ABCD'
B = 'AABC'
cs = CompareString()
print(cs.compare(A, B))
def hs1(a, b):
a1 = list(a)
b1 = list(b)
for c in b1:
if c in a1:
a1.remove(c)
else:
return print(False)
return print(True)
a = input("输入字符串A:")
b = input("输入字符串B:")
hs1(a, b)
本帖最后由 阴阳神万物主 于 2019-10-25 23:01 编辑
呐,不如咱们开个困难模式吧?
咱们目标是从某个神奇仓库中取出一些东西。字符串 A 就是仓库的库存,每一样东西都用首字母大写的单词(单词中不出现空格,有空格的单词空格用短横线替换,比如:Ice cream 在字符串中为 Ice-cream)表示,每个单词用空格分开,在字符串中出现的次数即这个东西的数量
字符串 B 是想要取出的东西的表单,格式与 A 相同
示例:
A = "Ball Ball Ball Knife Knife Condom Ice-cream",B = "Ball Condom Ball"
输出:True
审核正误,就交给楼主怎样?
楼主允许了的话,这题成立,明天我就把我的代码贴出来。
def echo(A,B):
A , B = list(A),list(B)
for i in B:
if i in A:
A.remove(i)
else:
return False
return True
def solution(A: str, B:str) -> bool:
import collections
AC = collections.Counter(A)
BC = collections.Counter(B)
for i in BC:
v = AC.get(i, 0)
if v == 0 or v<BC:
return False
return True
def per(A,B):
for i in range(len(B)):
if B not in A:
print('False')
break
print('True')
def kao(A, B):
alst, blst = list(A), list(B)
alst.sort()
blst.sort()
beg = 0
a = ''.join(alst)
for i in blst:
z=a.find(i, beg)
if z >= 0:
beg = z + 1
else:
return False
else:
return True
A = "ABCD"
B = "ABC"
print(kao(A, B))
def pick(A,B):
a_list=list(A)
b_list=list(B)
for i in b_list:
try :
a_list.remove(i)
except:
return False
return True
def fun(A,B):
if sum(map(lambda x:x in A,B))==len(B):
print('True')
else:
print('False')
fun(A='ABCD',B='AABC')
def pick(A,B):
a_list=list(A)
for i in B:
try :
a_list.remove(i)
except:
return False
return True
阴阳神万物主 发表于 2019-10-25 23:00
呐,不如咱们开个困难模式吧?
咱们目标是从某个神奇仓库中取出一些东西。字符串 A 就是仓库的库存,每一 ...
这题可以,但是你要提供测试数据
XiaoPaiShen 发表于 2019-10-25 22:11
恭喜通过!
执行用时:101 ms
路经此处 发表于 2019-10-25 22:31
def hs1(a, b):
a1 = list(a)
b1 = list(b)
恭喜通过!
执行用时:202 ms
angtn 发表于 2019-10-25 23:33
恭喜通过!
执行用时:151 ms
战场原 发表于 2019-10-26 00:40
def solution(A: str, B:str) -> bool:
import collections
AC = collections.Counter(A)
恭喜通过!
执行用时:101 ms
18511353234 发表于 2019-10-26 07:07
输入:A = "ABCD", B = "AABC"
输出:True
预期结果:False
kaohsing 发表于 2019-10-26 08:40
恭喜通过!
执行用时:101 ms
findland 发表于 2019-10-26 11:07
def pick(A,B):
a_list=list(A)
b_list=list(B)
恭喜通过!
执行用时:101 ms
动心成神 发表于 2019-10-26 11:21
输入:A = "ABCD", B = "AABC"
输出:True
预期结果:False