본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 10698 번 : Ahmed Aly

반응형

https://www.acmicpc.net/problem/10698

 

10698번: Ahmed Aly

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Followed by T lines, each test case is a single line containing an equation in the following format

www.acmicpc.net

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

test case 수 t, a op b = res 형태의 수식을 받을 수 있도록 변수를 선언 후 입력받습니다.

📔 정답출력

실제 결과값을 계산해 반환하는 getActualResult함수를 수행해 이 값이 res와 다르다면 YES를 아니라면 NO를 형식에 맞게 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t, a, b, res;
char op, eq;

int getActualResult(){
  if(op == '+') return a + b;
  if(op == '-') return a - b;
}

int main(){
  cin >> t;
  for(int i = 1; i <= t; i++){
    cin >> a >> op >> b >> eq >> res;
    cout << "Case "<< i << ": ";
    if(getActualResult() == res) cout << "YES\n";
    else cout << "NO\n";
  }
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.