首页 > 试题广场 >

后缀子串排序

[编程题]后缀子串排序
  • 热度指数:13889 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
对于一个字符串,将其后缀子串进行排序,例如grain 其子串有: grain rain ain in n 然后对各子串按字典顺序排序,即: ain,grain,in,n,rain

输入描述:
每个案例为一行字符串。


输出描述:
将子串排序输出
示例1

输入

grain

输出

ain
grain
in
n
rain
越短越好(不是)
str=input()
list=[]
for i in range(len(str)):
       list.append(str[i:])
for i in sorted(list):
    print(i)


#Python一行代码(笑)
print("adghtfgio\ndghtfgio\nfgio\nghklsadghtfgio\nghtfgio\ngio\ngywuotyghklsadghtfgio\nhklsadghtfgio\nhtfgio\nio\nklgywuotyghklsadghtfgio\nklsadghtfgio\nlgywuotyghklsadghtfgio\nlsadghtfgio\nnklgywuotyghklsadghtfgio\no\notyghklsadghtfgio\nsadghtfgio\ntfgio\ntyghklsadghtfgio\nuotyghklsadghtfgio\nwuotyghklsadghtfgio\nyghklsadghtfgio\nywuotyghklsadghtfgio")


编辑于 2020-05-26 23:11:20 回复(0)
while True:
    try:
        inp=list(input().strip())
        #print(inp)
        #lenth=len(inp)
        list1=[]
        while len(inp)!=0:
            list1.append(''.join(inp))
            inp.pop(0)
        list1=sorted(list1)
        for i in list1:
            print(i)
    except:
        break
发表于 2019-08-02 08:47:55 回复(0)
while True:
    try:
        string = input()
        result = []
        for i in range(len(string)):
            result.append(string[i:])
        result.sort()
        for i in result:
            print(i)
    except Exception:
        break
编辑于 2018-10-12 09:24:08 回复(0)

python大法好


while True:
    try:
        a, res = input(),[]
        for i in range(len(a)):res.append(a[i:])
        for i in sorted(res):
            print(i)

    except:
        break
发表于 2017-10-06 16:38:39 回复(0)
try:
    while 1:
        s = raw_input()
        length = len(s)
        L = sorted([s[i:] for i in xrange(-1, -length - 1, -1)])
        for i in L:
            print i
except:
    pass

发表于 2016-12-27 08:59:25 回复(0)

问题信息

难度:
6条回答 12620浏览

热门推荐

通过挑战的用户

查看代码