一个长度为 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"))