문제
You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.
Given the ages of the youngest and middle children, what is the age of the oldest child?
입력
The input consists of two integers, each on a separate line. The first line is the age Y of the youngest child (0 ≤ Y ≤ 50). The second line is the age M of the middle child (Y ≤ M ≤ 50).
출력
The output will be the age of the oldest child.
Solved.ac 레벨
브론즈 IV
풀이
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a, b;
cin >> a >> b;
cout << b + (b - a) << "\n";
return 0;
}
'Study (etc) > Problem Solving' 카테고리의 다른 글
[BOJ / C++] 27866번 : 문자와 문자열 (0) | 2023.03.16 |
---|---|
[BOJ / C++] 14489번 : 치킨 두 마리 (...) (0) | 2023.03.16 |
[BOJ / C++] 4948번 : 베르트랑 공준 (0) | 2023.03.13 |
[BOJ / C++] 2688번 : 줄어들지 않아 (0) | 2023.03.13 |
[BOJ / C++] 10828번 : 스택 (0) | 2023.03.10 |