먼저 문자열을 입력받고 charAt메소드로 문자들을 아스키코드값으로 나눠 준다. 그 후 대문자 아스키코드 값 A~Z, 즉 65~90 까지의 값들을 for문으로
그 알파벳들에 맞는 시간들을 배열에 넣는다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args){ | |
int[] a1 = new int[15]; | |
int[] a2 = new int[15]; | |
int cnt=3; //각 다이얼 별로 알파벳들이 들어있는 크기를 구하기 위한 변수 | |
int init =0; //각 다이얼 별 필요 시간 | |
int x=0; //값을 카운터 해주기 위해 필요 | |
int result =0; // 필요 시간을 모두 더한 값 | |
Scanner sc = new Scanner(System.in); | |
String a = sc.nextLine(); | |
for(int i=0; i<a.length(); i++) { | |
a1[i] = a.charAt(i); | |
for(int j=65; j<=90; j++) { | |
if(x==cnt) { | |
x=0; | |
init++; | |
if(init==5) { | |
cnt=cnt+1; | |
}else if(init==6) { | |
cnt=cnt-1; | |
}else if(init==7) { | |
cnt=cnt+1; | |
} | |
} | |
if(a1[i]==j) { | |
a2[i]=init+3; | |
} | |
x++; | |
} | |
cnt=3; | |
init=0; | |
x=0; | |
} | |
for(int i=0; i<a.length(); i++) { | |
result +=a2[i]; | |
} | |
System.out.println(result); | |
} | |
} |
'백준 알고리즘 > JAVA' 카테고리의 다른 글
[JAVA 자바] 백준 2775번 부녀회장이 될테야 (0) | 2018.07.13 |
---|---|
[JAVA 자바] 백준 2941번 크로아티아 알파벳 (0) | 2018.07.12 |
[JAVA 자바] 백준 2908번 상수 (0) | 2018.07.12 |
[JAVA 자바] 백준 1011번 Fly me to the Alpha Centauri (2) | 2018.07.12 |
[JAVA 자바] 백준 1316번 그룹 단어 체커 (0) | 2018.07.11 |