ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [java] 백준 알고리즘 10809번 알파벳 찾기 풀이
    알고리즘/백준 알고리즘 2018. 5. 19. 10:59



    * 풀이 소스


    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    public class Baekjoon10809 {
     
        public static void main(String[] args) throws NumberFormatException, IOException {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
            
            String s = br.readLine();
     
            /* for문보다 바로 선언해주는게 빠를 것 같았다 */
            // 선언이 되어있지 않다면 -1을 선언해주기 위함이다
            int[] alphabet = new int[] {-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1};
            
            for(int i=0; i<s.length(); i++) {
                switch(String.valueOf(s.charAt(i))) { // 위치는 조건대로 0번부터 시작한다
                    case "a":
                        if(alphabet[0== -1) { // 각 조건마다 -1을 체크하지 않으면 중복된 알파벳이 있으면 마지막에 온 알파벳 인덱스로 
                            alphabet[0= i;
                        }
                        break;
                    case "b":
                        if(alphabet[1== -1) {
                            alphabet[1= i;
                        }    
                        break;
                    case "c":
                        if(alphabet[2== -1) {
                            alphabet[2= i;
                        }
                        break;
                    case "d":
                        if(alphabet[3== -1) {
                            alphabet[3= i;
                        }
                        break;
                    case "e":
                        if(alphabet[4== -1) {
                            alphabet[4= i;
                        }    
                        break;
                    case "f":
                        if(alphabet[5== -1) {
                        alphabet[5= i;
                        }
                        break;
                    case "g":
                        if(alphabet[6== -1) {
                            alphabet[6= i;
                        }    
                        break;
                    case "h":
                        if(alphabet[7== -1) {
                            alphabet[7= i;
                        }    
                        break;
                    case "i":
                        if(alphabet[8== -1) {
                            alphabet[8= i;
                        }
                        break;
                    case "j":
                        if(alphabet[9== -1) {
                            alphabet[9= i;
                        }    
                        break;
                    case "k":
                        if(alphabet[10== -1) {
                            alphabet[10= i;
                        }    
                        break;
                    case "l":
                        if(alphabet[11== -1) {
                            alphabet[11= i;
                        }    
                        break;
                    case "m":
                        if(alphabet[12== -1) {
                            alphabet[12= i;
                        }
                        break;
                    case "n":
                        if(alphabet[13== -1) {
                            alphabet[13= i;
                        }    
                        break;
                    case "o":
                        if(alphabet[14== -1) {
                            alphabet[14= i;
                        }    
                        break;
                    case "p":
                        if(alphabet[15== -1) {
                            alphabet[15= i;
                        }
                        break;
                    case "q":
                        if(alphabet[16== -1) {
                            alphabet[16= i;
                        }    
                        break;
                    case "r":
                        if(alphabet[17== -1) {
                            alphabet[17= i;
                        }    
                        break;
                    case "s":
                        if(alphabet[18== -1) {
                            alphabet[18= i;
                        }    
                        break;
                    case "t":
                        if(alphabet[19== -1) {
                            alphabet[19= i;
                        }    
                        break;
                    case "u":
                        if(alphabet[20== -1) {
                            alphabet[20= i;
                        }
                        break;
                    case "v":
                        if(alphabet[21== -1) {
                            alphabet[21= i;
                        }
                        break;
                    case "w":
                        if(alphabet[22== -1) {
                            alphabet[22= i;
                        }    
                        break;
                    case "x":
                        if(alphabet[23== -1) {
                            alphabet[23= i;
                        }    
                        break;
                    case "y":
                        if(alphabet[24== -1) {
                            alphabet[24= i;
                        }    
                        break;
                    case "z":
                        if(alphabet[25== -1) {
                            alphabet[25= i;
                        }    
                        break;    
                }
            }
            
            for(int output: alphabet) {
                bw.write(output+ " ");
            }
            bw.flush();
        }    
    }
     
    cs


Designed by Tistory.