[문제]
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.
영어라서 그렇지, 문제 자체는 매우 기초적인 문제이다!
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include <stdio.h>
int main()
{
int youngest, middle;
scanf("%d %d", &youngest, &middle);
printf("%d\n", middle + (middle-youngest));
return 0;
}
|
cs |
출처: https://www.acmicpc.net/problem/6749
'코딩 문제풀이 및 연습 > [C언어]백준' 카테고리의 다른 글
[백준 10818번] 최소, 최대 (0) | 2021.03.18 |
---|---|
[백준 2675번]문자열 반복 (0) | 2021.03.16 |
[백준 9012번] Parenthesis (0) | 2020.10.08 |
[백준 2795번] Transactions (0) | 2020.09.05 |
[백준 2753번] 윤년 (0) | 2020.09.05 |