์ฒด๊ฐ Level : โ
โโ Review: ๋ฌธ์์ด ์๋ฅด๊ธฐ, ์๋ฅธ ๊ฐ ์์ฉํ๊ธฐ 2์ฐจ์๋ฐฐ์ด์ ์ฌ์ฉํ๊ฒ๋ผ์ 2์ค for๋ฌธ ์ฌ์ฉํด์ผํ๋ ๋ณต์กํด์ง๊ฒ ๋ค ์ถ์๋๋ฐ for๋ฌธ 1๊ฐ๋ก ์ ์ฒ๋ฆฌ๋ผ์ ์ฌ์ ๋ค! |
๐ก ๋ฌธ์์ด๋ก ์ฃผ์ด์ง๋ ์์ด ๋ง๋ ์์ธ์ง ํ๋ณํ๊ณ X O ๋ฅผ ๋ฐํํด์ค๋ค.
1) ๋ฌธ์์ด ์๋ฅด๊ธฐ split(" ")
2) ์๋ฅธ ๋ฌธ์์ด์ ๋ณด๊ดํ 2์ฐจ์ ๋ฐฐ์ด ์์ฑํ๊ธฐ tmp[][]
3) ๋ฌด์กฐ๊ฑด tmp ์๋ฆฌ์ ๋ค์ด์ค๋ ๊ฐ์ ํต์ผ์ด ๋๋ค. => tmp[x][1] ๋ฌด์กฐ๊ฑด ์ฐ์ฐ์, tmp[x][3] ๋ฑํธ๊ฐ ๋๋ค.
4) tmp[x][0] ,[2], [4] ๋ ๋ฌธ์์ด์ด๊ธฐ ๋๋ฌธ์ ์ ์๋ก ๋ณํํด์ ์ฐ์ฐ์ ์คํํด์ค๋ค.
class Solution {
public String[] solution(String[] quiz) {
String[] answer = new String[quiz.length];
String[][] tmp = new String[quiz.length][5];
int sum = 0;
for (int i = 0 ; i < tmp.length; i++){
tmp[i] = quiz[i].split(" ");
if ( tmp[i][1].equals("+")){
sum = Integer.valueOf(tmp[i][0]) + Integer.valueOf(tmp[i][2]);
if ( sum == Integer.valueOf(tmp[i][4])){
answer[i] = "O";
}else {
answer[i] = "X";
}
}else {
sum = Integer.valueOf(tmp[i][0]) - Integer.valueOf(tmp[i][2]);
if (sum == Integer.valueOf(tmp[i][4])){
answer[i] = "O";
}else {
answer[i] = "X";
}
}
}
return answer;
}
}