P1321 单词覆盖还原 python代码
作者:互联网
题目描述:
一个长度为 3<=l≤255) 的字符串中被反复贴有 boy 和 girl 两单词,后贴上的可能覆盖已贴上的单词(没有被覆盖的用句点表示),最终每个单词至少有一个字符没有被覆盖。问贴有几个 boy 几个 girl?
str1 = input()
# 制作两个列表
# boy
b = ["boy","bo","oy","b","o","y"]
g = ["girl","gir","irl","gi","ir","rl","g","i","r","l"]
# 男生替换成1
for i in b:
str1 = str1.replace(i, "1")
# 女生替换成2
for i in g:
str1 = str1.replace(i, "2")
print(str1.count("1"))
print(str1.count("2"))
标签:count,boy,python,str1,替换成,replace,单词,P1321,print 来源: https://blog.csdn.net/qq872890060/article/details/121125332