공부기록/백준

[백준] 5637번 가장 긴 단어

메델 2023. 11. 21. 03:47
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input;
        String longestWord = "";

        while (!(input = scanner.next()).equals("E-N-D")) {
            String cleanedWord = input.replaceAll("[^a-zA-Z-]", "");
            if (cleanedWord.length() > longestWord.length()) {
                longestWord = cleanedWord;
            }
        }

        System.out.println(longestWord.toLowerCase());
    }
}