python
2026-05-16 21:42:02
发布于:江苏
1阅读
0回复
0点赞
import sys
def main():
# 读取输入
data = sys.stdin.read().splitlines()
if len(data) < 2:
return
s1 = data[0].strip() # 单词
s2 = data[1] # 文章,可能包含空格,保持原样
target = s1.lower()
n = len(s2)
count = 0
first_pos = -1
i = 0
while i < n:
# 跳过空格
if s2[i] == ' ':
i += 1
continue
# 找到一个单词的起始
start = i
# 找单词结束
while i < n and s2[i] != ' ':
i += 1
word = s2[start:i].lower()
if word == target:
count += 1
if first_pos == -1:
first_pos = start
# 继续循环,此时i指向空格或末尾
if count > 0:
print(count, first_pos)
else:
print(-1)
if __name__ == "__main__":
main()
这里空空如也

有帮助,赞一个