문제 링크입니다: www.acmicpc.net/problem/2997
2997번: 네 번째 수
첫째 줄에 상근이가 고른 네 개의 숫자 중 세 개가 주어진다. 이 숫자는 크기 순이 아닐 수도 있고, -100보다 크거나 같고, 100보다 작거나 같은 정수이다.
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
vector<int> v(3); | |
for (int i = 0; i < 3; i++) | |
{ | |
cin >> v[i]; | |
} | |
sort(v.begin(), v.end()); | |
int diff = v[1] - v[0]; | |
int diff2 = v[2] - v[1]; | |
if (diff == diff2) | |
{ | |
cout << v[2] + diff << "\n"; | |
} | |
else if (diff > diff2) | |
{ | |
cout << v[0] + diff2 << "\n"; | |
} | |
else | |
{ | |
cout << v[1] + diff << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 3058번 짝수를 찾아라 (0) | 2021.05.14 |
---|---|
백준 6757번 팰린드롬 진법 (2) | 2021.05.13 |
백준 2991번 사나운 개 (0) | 2021.05.11 |
백준 2985번 세 수 (0) | 2021.05.10 |
백준 2975번 Transactions (0) | 2021.05.09 |