Last active
March 9, 2018 04:04
-
-
Save qkreltms/5366f31dc4406e373a63e73b984e2a54 to your computer and use it in GitHub Desktop.
카카오톡 신입 공채 1, 2번 문제
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
package algorithm; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** | |
* @author jack | |
* | |
*/ | |
public class kakao2 { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String user = br.readLine(); | |
Pattern p1 = Pattern.compile("[0-9]+"); // 0-9인 문자가 하나 이상 있다. | |
Pattern p2 = Pattern.compile("[A-Z]+#*\\**"); // A-Z인 문자가 하나 이상 있고, #, *은 있을 수도 있고 없을 수도 있고 | |
Matcher m1 = p1.matcher(user); | |
Matcher m2 = p2.matcher(user); | |
int[] sum = new int[3]; | |
for (int i = 0; i < 3; i++) { | |
m1.find(); | |
m2.find(); | |
int point = Integer.parseInt(m1.group()); | |
char bonus = m2.group().charAt(0); | |
switch (bonus) { | |
case 'D': | |
sum[i] = (int) Math.pow(point, 2); | |
break; | |
case 'T': | |
sum[i] = (int) Math.pow(point, 3); | |
break; | |
default : | |
sum[i] = point; | |
} | |
if (m2.group().length() >= 2) { //문자열 뒤에 옵션이 있을 때 | |
char option = m2.group().charAt(1); | |
if (option == '*') { | |
if (i >= 1) { //두 번째부터 이전 것도 곱한다. | |
sum[i-1] *= 2; | |
} | |
sum[i] *= 2; | |
} else if (option == '#') { | |
sum[i] *= -1; | |
} | |
} | |
} | |
int result = sum[0] + sum[1] + sum[2]; | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment