[C++] 백준 13420 : 사칙연산

Kim Nahyeong·2022년 3월 25일
0

백준

목록 보기
124/157

#include <iostream>

int N;
long long a, b, c; // 32 비트 말고 64 비트
char oper[2];
bool answer = true; // 정답
int main(int argc, char** argv){
  scanf("%d", &N);

  for(int i = 0; i < N; i++){
    scanf("%lld %c %lld %c %lld", &a, &oper[0], &b, &oper[1], &c);

    if(oper[0] == '+'){
      if(a + b != c){
        answer = false;
      }
    } else if(oper[0] == '-'){
      if(a - b != c){
        answer = false;
      }
    } else if(oper[0] == '*'){
      if(a * b != c){
        answer = false;
      }
    } else if(oper[0] == '/'){
      if(a / b != c){
        answer = false;
      }
    }

    if(answer){
      printf("correct\n");
    } else {
      printf("wrong answer\n");
    }

    answer = true; // 초기화
  }

  return 0;
}

오늘은 머리가 잘 안 돌아가서 그냥 잊지 않기 위한 쉬운 문제로 하루치 대신하기... 내일은 다시 짱이 되어야지

  • 32bit 정수까지라고 하면 int형이 가능이지만 64bit 정수라면 long long을 써야한다. 그것때문에 한 번 틀렸다... 항상 수의 범위 잘 생각하기

0개의 댓글