코딩로그
[백준/BOJ/C++] 9950번 Rectangles 본문
[문제]
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";
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 9947번 Coin tossing (0) | 2021.11.05 |
---|---|
[백준/BOJ/C++] 9948번 Have you had your birthday yet? (0) | 2021.11.02 |
[백준/BOJ/C++] 4575번 Refrigerator Magnets (0) | 2021.11.02 |
[백준/BOJ/C++] 15238번 Pirates (0) | 2021.11.02 |
[백준/BOJ/C++] 4589번 Gnome Sequencing (0) | 2021.11.02 |