코딩로그
[백준/BOJ/C++] 6749번 Next in line 본문
[문제]
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.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int first, second, third;
cin >> first;
cin >> second;
third = second + (second - first);
cout << third;
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 9085번 더하기 (0) | 2021.10.12 |
---|---|
[백준/BOJ/C++] 17388번 와글와글 숭고한 (0) | 2021.10.12 |
[백준/BOJ/C++] 4562번 No Brainer (0) | 2021.10.12 |
[백준/BOJ/C++] 4101번 크냐? (0) | 2021.10.12 |
[백준/BOJ/C++] 2752번 세수정렬 (0) | 2021.10.12 |