본문 바로가기
  • Let's study
PS/백준

[C++] 백준 25784: Easy-to-Solve Expressions

by 코딩고수이고파 2023. 5. 13.

문제

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

 

25784번: Easy-to-Solve Expressions

When one looks at a set of numbers, one usually wonders if there is a relationship among them? This task is more manageable if there are only three numbers. Given three distinct positive integers, you are to determine how one can be computed using the othe

www.acmicpc.net

 

해결방법

세 수를 배열에 넣어 정렬한 뒤, 첫번째 수두번째 수더하거나 곱한세번째 수와 같은지 확인하여 조건에 맞게 출력한다.

 

코드

#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int arr[3];

	for (int i = 0; i < 3; i++) {
		cin >> arr[i];
	}

	sort(arr, arr + 3);

	if (arr[0] + arr[1] == arr[2])
		cout << 1;
	else if (arr[0] * arr[1] == arr[2])
		cout << 2;
	else
		cout << 3;

	return 0;
}

'PS > 백준' 카테고리의 다른 글

[C++] 백준 5358: Football Team  (0) 2023.05.15
[C++] 백준 6825: Body Mass Index  (0) 2023.05.14
[C++] 백준 6887: Squares  (0) 2023.05.12
백준 18698: The Walking Adam  (0) 2023.05.11
[C++] 백준 5300: Fill the Rowboats!  (0) 2023.05.10

댓글