結果

問題 No.2268 NGワード回避
ユーザー kusagame12
提出日時 2023-11-07 21:02:07
言語 Java
(openjdk 23)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 75,596 KB
実行使用メモリ 45,824 KB
最終ジャッジ日時 2024-09-25 23:27:42
合計ジャッジ時間 12,577 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        List<String> ngWords = new ArrayList<>();
        while(sc.hasNext()){
            ngWords.add(sc.next());
        }

        sc.close();
        
        char a = 'a';
        char b = 'b';
        StringBuilder sb = new StringBuilder();
        for(int i = 0 ; i < n ; i++){
            sb.append(a);
        }
        
        for(int i = 0 ; i < n ; i++){
            String str = sb.toString();
            if(!ngWords.contains(str)){
                System.out.println(str);
                return;
            }
            sb.setCharAt(i , b);
        }
        
        System.out.println(sb.toString());
        
    }
    
}
0