반응형
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";
}
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 2712 : 미국 스타일 (0) | 2022.07.27 |
---|---|
(C++) - 백준(BOJ) 24724번 : 현대모비스와 함께하는 부품 관리 (0) | 2022.07.26 |
(C++) - 백준(BOJ) 25377 번 : 빵 (0) | 2022.07.22 |
(C++) - 백준(BOJ) 2083 : 럭비클럽 (0) | 2022.07.21 |
(C++) - 백준(BOJ) 2083 : 럭비클럽 (0) | 2022.07.20 |