DNA序列可顺时针滚定的序列组合中,找出字典序最小的那一种。
s = list(input())
# print(s)
cur = []
for i in s:
cur.append(ord(i))
all_p = []
for i in range(len(s)):
temp = cur[i:] + cur[:i]
all_p.append(temp)
all_p.sort()
# # print(all_p)
res = [chr(i) for i in all_p[0]]
print(''.join(res))
族谱还原 from collections import defaultdict, deque
N = int(input())
strs = []
for i in range(N):
temp = list(input().split())
strs.append(temp)
num = int(input())
acc = defaultdict(set)
for it in strs:
for i in range(len(it)-1, 0, -1):
acc[it[i-1]].add(it[i])
# print(acc)
for i in acc:
flag = 1
for son in acc.values():
if i in son:
flag = 0
if flag == 1:
father = i
break
que = deque([father])
res = []
while que:
size = len(que)
path = []
for _ in range(size):
cur = que.popleft()
path.append(cur)
if cur in acc:
que.extend(acc[cur])
res.append(path)
print(father)
print(len(res[-1]))
#字节跳动##字节跳动笔试##许愿字节求上岸#