Playground/자바문제집

[백준] 10809번

미숫가루설탕많이 2023. 1. 22. 20:44
import java.util.*;
import java.io.*;

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

      int[] arr = new int[26];   // 알파벳

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

      String data = sc.nextLine();

      for (int i = 0; i < data.length(); i++) {
         char ch = data.charAt(i);

         if (arr[ch - 'a'] == -1) { // 처음 등장하는 위치이므로
            arr[ch - 'a'] = i;
         }
      }
      for (int ans : arr) {
         System.out.print(ans + " ");
      }
   }
}

'Playground > 자바문제집' 카테고리의 다른 글

[백준] 9086번  (0) 2023.01.22
[백준] 11718번  (0) 2023.01.22
[백준] 2754번  (0) 2023.01.22
[백준] 2744번  (0) 2023.01.22
[백준] 2743번  (0) 2023.01.22