728x90
SMALL

public class Solution {
    public string[] solution(string[] quiz) {
        string[] answer = new string[quiz.Length];
        
        for(int i = 0; i < quiz.Length; i++)
        {
            answer[i] = oxCheck(quiz[i].Split(" "));
        }
        return answer;
    }
    
    public string oxCheck(string[] str)
    {
        int num = int.Parse(str[0]);

/// 첫 번째 숫자
        
        for(int i = 1; i < str.Length; i++) // 1부터 한다.
        {

///홀수 번째 일때는 연산자니까 
            if(i % 2 != 0)
            {
                if(str[i].Equals("+"))
                {
                    num += int.Parse(str[i + 1]);

/// 플러스면 더하고
                }
                else if(str[i].Equals("-"))
                {
                    num -= int.Parse(str[i + 1]);

/// 마이너스면 뺀다.
                }
                else
                {
                    if(int.Parse(str[i + 1]) == num)
                    {
                        return "O";
                    }
                    else
                    {
                        return "X";
                    }
                }
            }
        }
        
        return "";
    }
}

 

 

 

 

자바

 

 

 

class Solution {
    public String[] solution(String[] quiz) {

        int size = quiz.length;
        String[] answer = new String[size];
        
        for (int i = 0; i < answer.length; i++) 
        {
            String[] splitQ = quiz[i].trim().split(" ");
            int X = Integer.parseInt(splitQ[0]);
            int Y = Integer.parseInt(splitQ[2]);
            int Z = Integer.parseInt(splitQ[4]);
            int cal = 0;
            
            if(splitQ[1].equals("-"))
            {
                cal = X - Y;
            }
            else
            {
                cal = X + Y;
            }

            answer[i] = Z == cal ? "O" : "X";
        }

        return answer;
    }
}

 

 

 

 

class Solution {
    public String[] solution(String[] quiz) {
        String[] answer = new String[quiz.length];

        for(int i=0; i<quiz.length; i++)
        {
            String[] temp = quiz[i].split(" ");
            
            if(temp[0].isEmpty())
            {
                answer[i]="O";
                continue; 
            }
            
            Integer first = Integer.parseInt(temp[0]);
            String oper = temp[1];
            Long second = Long.parseLong(temp[2]);
            Integer result = Integer.parseInt(temp[4]);

            if(oper.equals("+"))
            {
                if(first+second==result)
                {
                    answer[i] = "O";
                } 
                else 
                {
                    answer[i] = "X";
                }
            } 
            else 
            {
                if(first-second==result)
                {
                    answer[i] = "O";
                } 
                else 
                {
                    answer[i] = "X";
                }
            }

        }


        return answer;
    }
}
728x90

설정

트랙백

댓글