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++] 9950번 Rectangles 본문

YJ/C++

[백준/BOJ/C++] 9950번 Rectangles

Team DAON 2021. 11. 2. 17:41

[문제]

My young son is struggling with his maths homework, can you help him please? He is working on the area of a rectangle – you know, area = length x width. His teacher has given him a table of lengths, widths and areas. Each row on the table has one of the 3 values missing; my son has to work out the missing value and write it in the table such that the values on each line represent the length, width and area of one rectangle.

[입력]

Input is a series of lines, each containing 3 integers, l, w, and a ( 0 ≤ l w ≤100, 0 ≤ a ≤ 10,000) representing the length, width and area of a rectangle in that order. The integers are separated by a single space. In each row, only one of the values has been replaced by a zero. The final row contains 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 the length, width or area as appropriate. The new value is always an integer.

[Source Code]

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	
	while(true){
		int a, b, c;
		cin >> a >> b >> c;

		if(a == 0 && b == 0 && c == 0)
			break;

		if(a == 0)
			cout << c / b << " " << b << " " << c << "\n";
		else if(b == 0)
			cout << a << " " << c/a << " " << c << "\n";
		else if(c == 0)
			cout << a << " " << b << " " << a*b << "\n";
	}
	
}

[결과 화면]