package net.ipipip0129.yukicoder.no701; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num_cnt = scan.nextInt(); String prev_str = "aaa"; List stringList = new ArrayList<>(); for (int i = 0; i < num_cnt - 1; i++) { while (true) { String moji = createRandomString(prev_str.charAt(0), prev_str.charAt(prev_str.length() - 1)); if (!stringList.contains(moji)) { stringList.add(moji); prev_str = moji; System.out.println(moji); break; } } } System.out.println(createRandomString(prev_str.charAt(0), 'n')); } public static String createRandomString(Character begin, Character end) { Random rand = new Random(); StringBuilder sb = new StringBuilder(); sb.append(begin); for (int i = 0; i < 18; i++) { sb.append(Character.toChars(rand.nextInt(26) + 97 )); } sb.append(end); return sb.toString(); } }