判斷字符串結尾方式

輸入2個字符串,判斷其中一個字符串是不是以另外一個字符串結尾python

輸入格式:

輸入2行,每行一個字符串數據code

輸出格式:

若是第1個字符串以第2個字符串結尾,輸出第2個字符串 若是第2個字符串以第1個字符串結尾,輸出第1個字符串 若是兩個字符串互爲對方的結尾字符,輸出'all' 若是都不知足,輸出'no'blog

輸入樣例:

abc123
123
 

輸出樣例:

123
a=input()
b=input()
x=len(a)
y=len(b)
c=-len(a)
d=-len(b)
if x>y:
    if a[d:]==b:
        print(b)
    else:
        print("no")
elif x<y:
    if a==b[c:]:
        print(a)
    else:
        print("no")
elif x==y:
    if a[c:]==b[c:]:
        print("all")
    else:
        print("no")
相關文章
相關標籤/搜索