problem AOR Ika wants to create a strong password that consists only of lowercase…
- User
problem
AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of of dangerous passwords by a friend, decided to create a password that meets all of the following conditions.
- The length is at least one character.
- Different from any contiguous substring of any dangerous password.
- This is the shortest character string that meets the conditions 1 and 2.
- This is the character string that comes to the beginning when arranged in lexicographic order while satisfying the conditions 1, 2, and 3.
Write a program to generate a strong password on behalf of AOR Ika-chan. input
Input is given from standard input in the following format.
Assistant
pythondef next_candidate(s): s_list = list(s) i = len(s_list) - 1 while i >= 0 and s_list[i] == 'z': s_list[i] = 'a' i -= 1 if i < 0: return None s_list[i] = chr(ord(s_list[i]) + 1) return ''.join(s_list) def main(): import sys input = sys.stdin.read().split() N = int(input[0]) S_list = input[1:N+1] current_L = 1 while True: substr_set = set() for s in S_list: len_s = len(s) if len_s < current_L: continue for i in range(len_s - current_L + 1): substr = s[i:i+current_L] substr_set.add(substr) candidate = 'a' * current_L while True: if candidate not in substr_set: print(candidate) return candidate = next_candidate(candidate) if candidate is None: break current_L += 1 if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.