※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 9776번 문제인 Max Volume이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/9776
9776번: Max Volume
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) which is the number of figures. The n following lines contain the description of each figure. In case of a cone, the line begins with letter C and followed by 2 values: r and h res
www.acmicpc.net
주어지는 N개의 입체도형의 부피 중 최댓값을 출력하는 문제이다.
충분한 정밀도를 가진 실수 자료형(long double)을 이용해 각 입체도형의 부피를 계산하고(지문에 공식이 주어져있다.) 문제를 해결해주자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <cmath>
using namespace std;
typedef long double ld;
int N;
ld ans;
ld PI = acos((ld)-1);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
while (N--) {
char c; cin >> c;
if (c == 'C') {
ld r, h; cin >> r >> h;
ans = max(ans, PI * r * r * h / 3);
}
else if (c == 'L') {
ld r, h; cin >> r >> h;
ans = max(ans, PI * r * r * h);
}
else {
ld r; cin >> r;
ans = max(ans, PI * r * r * r * 4 / 3);
}
}
cout << fixed;
cout.precision(3);
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 2566 // C++] 최댓값 (0) | 2023.02.04 |
---|---|
[BOJ 13939 // C++] Imena (0) | 2023.02.04 |
[BOJ 24622 // C++] Blocks (0) | 2023.02.03 |
[BOJ 22937 // C++] 교수님 계산기가 고장났어요! (0) | 2023.02.03 |
[BOJ 27297 // C++] 맨해튼에서의 모임 (0) | 2023.02.02 |