※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 4696번 문제인 St. Ives이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/4696
4696번: St. Ives
Input consists of multiple data sets. Each data set consists of a line with a single floating point number number representing the numbers of wives, sacks per wife, cats per sack, and kittens per cat that Robert encountered that year. End of input is indic
www.acmicpc.net
x가 주어질 때, 문제의 답은 지문에 나온 예와 유사하게 1과 x와 x*x와 x*x*x와 x*x*x*x의 합으로 나타나므로 이를 계산해 출력하는 것으로 문제를 해결할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long double ld;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout.precision(2);
ld x; cin >> x;
while (x) {
cout << 1 + x + x * x + x * x * x + x * x * x * x << '\n';
cin >> x;
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 25372 // C++] 성택이의 은밀한 비밀번호 (0) | 2022.10.30 |
---|---|
[BOJ 18698 // C++] The Walking Adam (0) | 2022.10.30 |
[BOJ 18198 // C++] Basketball One-on-One (0) | 2022.10.30 |
[BOJ 25600 // C++] Triathlon (0) | 2022.10.30 |
[BOJ 25635 // C++] 자유 이용권 (0) | 2022.10.29 |