[SWEA] 사칙연산 유효성 검사

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

사칙연산 ( +, -, * , / ) 가 아닌 경우만 찾아 0으로 리턴해준다.

JAVA Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.Scanner;
 
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int tc=1;tc<=10;tc++) {
            int res = 1;
            int n = Integer.parseInt(sc.nextLine());
            for(int i=0;i<n;i++) {
                String[] s = sc.nextLine().split(" ");
                if(s[1].charAt(0)==43 || s[1].charAt(0)==45 || s[1].charAt(0)==42 || s[1].charAt(0)==47 ){
                    if(s.length!=4) {
                    	res = 0;
                    }
                }
            }
            System.out.print("#"+tc+" "+res);
            System.out.println();
        }
    }
}