※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 24783번 문제인 Number Fun이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/24783
24783번: Number Fun
Ms. Greene is trying to design a game for her third-grade class to practice their addition, subtraction, multiplication, and division. She would like for every student in her class to be able to "think mathematically" and determine if any two given numbers
www.acmicpc.net
주어진 세 수가 x, y, z일 때 살펴봐야 하는 경우의 수는 다음과 같다.
1. x+y=z
2. x-y=z
3. y-x=z
4. x*y=z
5. x/y=z (정확히 나누어떨어져야 함: 예제입력의 5 3 1 참고)
6. y/x=z (정확히 나누어떨어져야 함: 위의 5 참고)
5와 6의 경우, 식을 적절히 바꿔 y*z=x와 x*z=y로 구현하면 나머지 연산에 신경쓰지 않고 편하게 구현할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T; cin >> T;
while (T--) {
int x, y, z; cin >> x >> y >> z;
if (x + y == z || x - y == z || y - x == z || x * y == z || y * z == x || x * z == y) cout << "Possible\n";
else cout << "Impossible\n";
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 3023 // C++] 마술사 이민혁 (0) | 2022.05.15 |
---|---|
[BOJ 6030 // C++] Scavenger Hunt (0) | 2022.05.15 |
[BOJ 24883 // C++] 자동완성 (0) | 2022.05.15 |
[BOJ 2961 // C++] 도영이가 만든 맛있는 음식 (0) | 2022.05.15 |
[BOJ 14011 // C++] Small PhD Restaurant (0) | 2022.05.14 |