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

[백준 10809번 ː 자바(JAVA)] 알파벳 찾기

by 그릿er 2020. 7. 14.

 

 

 

 

import java.util.*;

public class Baekjoon10809 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		int[] count = new int[26];
		String s = sc.nextLine();
		
		for(int i=0; i<count.length; i++) {
			count[i]=-1;
		}
		
		for(int i=0; i<s.length(); i++) {
			for(int j=0; j<alphabet.length; j++) {
				if(s.charAt(i)==alphabet[j])
					if(count[j]==-1)
						count[j] = i;
					else if(count[j]!=-1)
						continue;
			}
		}
		for(int i=0; i<count.length; i++) {
			System.out.print(count[i] + " ");

		}
		
		
		sc.close();

	}

}