※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 26592번 문제인 Triangle Height이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/26592 

 

26592번: Triangle Height

The first line will contain a single integer n that indicates the number of lines that follow. Each line will include the area and base length of a triangle with the two values separated by a single space. area base

www.acmicpc.net

각 테스트케이스마다 삼각형의 밑변의 길이와 넓이가 주어진다.

 

이를 이용해 삼각형의 높이를 구해 주어진 형식에 맞춰 출력하는 것으로 문제를 해결하자.

 

본문에도 써져있지만, (삼각형의 넓이) = (삼각형의 밑변의 길이) * (삼각형의 높이) / 2 의 관계가 성립한다. 이 식을 적절히 변형해 삼각형의 넓이와 밑변의 길이를 알 때 높이를 구하는 식을 구해낼 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;
typedef long double ld;

int T;
ld A, B;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cout << fixed;
	cout.precision(2);

	cin >> T;
	while (T--) {
		cin >> A >> B;
		cout << "The height of the triangle is " << (2 * A) / B << " units\n";
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 26546 // C++] Reverse  (0) 2022.12.19
[BOJ 6887 // C++] Squares  (0) 2022.12.19
[BOJ 1809 // GolfScript] Moo  (0) 2022.12.19
[BOJ 2377 // FreeBASIC] Pottery  (0) 2022.12.19
[BOJ 14337 // Visual Basic] Helicopter  (0) 2022.12.19

+ Recent posts