Python编程PTA题解大全——索引
Description:输入一个字符串,再输入两个字符,求这两个字符在字符串中的索引。
Input:
第一行输入字符串
第二行输入两个字符,用空格分开。
Output:反向输出字符和索引,即最后一个最先输出。每行一个。
Sample Input:
mississippi
s p
Sample Output:
9 p
8 p
6 s
5 s
3 s
2 s
str = input()
a, b = input().split()
i = len(str) - 1
str = str[::-1] #字符串反向
for ch in str:
if ch == a or ch == b:
print(i, ch)
i -= 1