코딩로그
[백준/BOJ/C++] 7581번 Cuboids 본문
[문제]
A cuboid is a 3 dimensional shape in which each of the six faces is a rectangle. Sally Jones, a primary school teacher, is giving her pupils some practice at calculating the volume of a cuboid. I am sure you remember that volume = length x width x height.
Sally has given her pupils a table of lengths, widths, heights and volumes. Each row on the table has one of the 4 values missing; the pupils have to work out the missing value and write it in the table such that the values on each line represent the length, width, height and volume of one cuboid.
[입력]
Input is a series of lines, each containing 4 integers, l, w, h and v representing the length, width height and volume of a cuboid in that order. The integers are separated by a single space. 0 < l, w, h <100, 0 < v < 100,000. In each row, one of the values has been replaced by a zero. The final row contains 0 0 0 0 and should not be processed.
[출력]
Output is the same series of lines but with the zero in each line replaced by the correct value for length, width, height or volume as appropriate. The new value is always an integer.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
while(true){
int a, b, c, d;
cin >> a >> b >> c >> d;
if(a == 0 && b == 0 &&c == 0 && d == 0)
break;
if(d == 0){
cout << a << " " << b << " " << c << " " << a*b*c << "\n";
}
else if(a == 0){
cout << d / (b*c) << " " << b << " " << c << " " << d << "\n";
}
else if(b == 0){
cout << a << " " << d / (a * c) << " " << c << " " << d << "\n";
}
else if(c == 0){
cout << a << " " << b << " " << d / (a*b) << " " << d << "\n";
}
else
cout << a << " " << b << " " << c << " " << d << "\n";
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 12517번 Centauri Prime (Small1) (0) | 2021.11.02 |
---|---|
[백준/BOJ/C++] 4593번 Rock, Paper, Scissors (0) | 2021.11.02 |
[백준/BOJ/C++] 5751번 Head or Tail (0) | 2021.11.02 |
[백준/BOJ/C++] 9699번 RICE SACK (0) | 2021.11.02 |
[백준/BOJ/C++] 13985번 Equality (0) | 2021.11.02 |