Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 7581번 Cuboids 본문

YJ/C++

[백준/BOJ/C++] 7581번 Cuboids

Team DAON 2021. 11. 2. 17:25

[문제]

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";
	}
}

[결과 화면]