본문 바로가기

Coding Test/백준

[백준/자바] 10809 - 알파벳 찾기

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int[] arr = new int[26];
        for(int i=0; i<26; i++){
            arr[i] = -1;
        }

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

        for(int num : arr){
            System.out.print(num + " ");
        }

        br.close();
    }
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();

        for(int i=97; i<=122; i++) {
            System.out.print(str.indexOf(i) + " ");
        }

        br.close();
    }
}