본문 바로가기
알고리즘 문제풀이/백준

[알고리즘/백준] 10809 알파벳 찾기(자바)

by jeonghaemin 2021. 9. 20.
728x90

문제

https://www.acmicpc.net/problem/10809

풀이 코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] answer = new int[26];
        Arrays.fill(answer, -1);

        String s = br.readLine();
        for (int i = 0; i < s.length(); i++) {
            if (answer[s.charAt(i) - 97] == -1) {
                answer[s.charAt(i) - 97] = i;
            }
        }

        for (int i : answer) {
            System.out.print(i + " ");
        }
    }
}

댓글