💻 문제



일단 이해하자🤔
- 숫자 한 칸에 1초씩 걸리므로 1을 걸려면 2초, 2를 걸려면 3초가 필요하다.
switch-case 문을 써서(코드를 수정했다) 배열을 이용해서 받은 문자마다 걸린 시간을 더했다.
👀 풀이
import java.io.*;
public class Main3 {
public static void main(String[] args) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = bfr.readLine();
char ch[] = new char[str.length()];
for(int i = 0; i < str.length(); i++) {
ch[i] = str.charAt(i);
}
char alpa[] = {'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 timeList[] = {3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10};
int time = 0;
for(int i = 0; i < 26; i++) {
for(int j = 0; j < ch.length; j++) {
if(ch[j] == alpa[i]) {
time += timeList[i];
}
}
}
bfw.write(String.valueOf(time));
bfr.close();
bfw.flush();
bfw.close();
}
}
아쉬웠던 점••
- 알파벳이 3개씩 분배(?)되어 있었다면
if를 사용해서 풀 수도 있었을 것 같은데 너무 1차원적인 방법으로 푼 것 같아 아쉽다. -> 배열을 이용한 방법으로 수정하였다!