알파뱃 갯수를 순서대로
출력한다 없으면 0
baekjoon
out
1 0 -1 -1 2 -1 -1 -1 -1 4 3 -1 -1 7 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
a가 1번째
b가 0번째
이 순서
code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import java.util.*; public class Main { public static void main(String[] args) { //97~122 아스키 a-z Scanner sc = new Scanner(System.in); String input = sc.nextLine().trim(); // String input = "baekjoon"; char[] output = new char[26]; int [] outInt = new int[26]; char buff; int out=0; boolean tf = false; for(int i=0 ; ; i++) { out = i+97; output[i] = (char) out; outInt[i] = -1; if(output[i] == 'z') break; } // System.out.println(Arrays.toString(output)); for(int i=0 ;i<output.length ; i++) { for(int j=0; j<input.length() ;j++) { buff = input.charAt(j); if(buff == output[i] && outInt[i] <= -1 ) { outInt[i] = j; } } } // System.out.println(Arrays.toString(outInt)); for(int i=0; i<outInt.length ; i++) { System.out.print(outInt[i]+" "); } } } |
'오락기 > codeWar' 카테고리의 다른 글
백준 1157 단어공부 (0) | 2018.05.25 |
---|---|
2675 백준 문자열반복 (0) | 2018.05.11 |
백준 11654 (0) | 2018.05.11 |
백준 10039 (0) | 2018.05.11 |
백준 2920 (0) | 2018.05.03 |