본문 바로가기
코딩테스트/백준

[백준/10809] 알파벳 찾기 (Java)

by wo__ongii 2025. 1. 2.
728x90

 

[풀이]

import java.util.Arrays;
import java.util.Scanner;

public class Day24 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int num[] = new int[26];
        //배열 초기화
        Arrays.fill(num, -1);
        for(int i=0;i<26;i++){
            //ascii코드값
            int ch = 'a'+i;
            for(int j=0;j<S.length();j++){
                if(S.charAt(j) == ch) num[i] = S.indexOf(ch);
            }
        }
        for(int i=0;i<num.length;i++){
            System.out.print(num[i]+" ");
        }
    }
}

 

728x90
반응형