#41124: python 簡單解法


ozasd6565@gmail.com (Z O)

學校 : 不指定學校
編號 : 238164
來源 : [220.157.125.174]
最後登入時間 :
2024-09-06 21:35:07
o078. 3. 缺字問題 -- 2024年6月APCS | From: [220.157.125.174] | 發表日期 : 2024-07-05 23:21

 

# K = list('dp')
# L= int('3')
# S = 'dddppdpd'


K = list(input())
L = int(input())
S = input()


now_string = [ '' ] * L
cut_results = set() # 用集合去做搜尋 能夠更快且避免 TLE
end = False

def dfs(now_position):
    global end
    if end == True :
        return 
    if now_position == L : 
        new_string = ''
        for i in now_string:
            new_string+= i
        # print(new_string)
        if(new_string not in cut_results):
            end = True
            print(new_string)
        return 
        
    
    for i in K:
        now_string[now_position] = i
        dfs(now_position+1)
        
    
    
    
    
# 先產生 dddppdpd 的所有可能
for i in range(0,len(S),1):
    text = S[i:i+L]
    if len(text) == L:
        cut_results.add(text)
        
dfs(0)


    
    

 
ZeroJudge Forum