2022年5月1日 星期日

字串小程式

 s = 'abcdeckba'

n = len(s)
a=[]

 # test5

# def f(s,c,n):
#     if c==n:
#         print()
#         return
#     print(s[c],end=' ')
#     return f(s,c+1,n)
# f(s,0,n)

# test4
# def f(s,c,n):
#     if c==n:
#         print()
#         return
#     print(s[c:]+s[:c],end=' ')
#     return f(s,c+1,n)
# f(s,0,n)

# test3
# def f(s,c,n):
#     if c==n:
#         print()
#         return
#     print(s[c:]+s[:c],end=' ')
#     return f(s,c+1,n)
# f(s,0,n)
# test1
# def f(s,x):
#     if x==n:
#         return
#     a.append(s[:x])
#     return f(s,x+1)
# f(s,0)
# print(a)

# test2
# for p in range(len(s)):
#     # p = n//2
#     rStr = s[p]
#     preStr =s[:p]
#     preStr = preStr[::-1]
#     postStr = s[p+1:]
#     # print(preStr,postStr)
#     for i in preStr:
#         if i in postStr:
#             if abs(preStr.find(i)- postStr.find(i))<=2:
#                 rStr = i + rStr + i
#                 t = list(preStr)
#                 t = t.remove(i)
#                 # print(t)
#                 if t:
#                     preStr = ''.join(t)
#                 else:
#                     preStr = ''
#                 t = list(postStr)
#                 t = t.remove(i)
#                 if t:
#                     postStr = ''.join(t)
#                 else:
#                     postStr = ''
#     print(rStr)

沒有留言:

張貼留言