![[백준 / BOJ] 4153번 직각삼각형 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcPSFGf%2FbtrJn6DApnY%2Fdu43Av58prui3N1FPLXvYk%2Fimg.png)
[백준 / BOJ] 4153번 직각삼각형 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 4. 9. 18:11
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/1085
1085번: 직사각형에서 탈출
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램
www.acmicpc.net
문제

문제 풀이
피타고라스 정리를 코드로 구현하면 된다.
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
int x, y, z; | |
cin >> x >> y >> z; | |
while (x && y && z) { | |
if (x > y) | |
swap(x, y); | |
if (y > z) | |
swap(y, z); | |
if (z * z == x * x + y * y) | |
cout << "right\n"; | |
else | |
cout << "wrong\n"; | |
cin >> x >> y >> z; | |
} | |
return 0; | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
arr = list(map(int, input().split())) | |
if sum(arr) == 0: | |
break | |
l = max(arr) | |
arr.remove(l) | |
if arr[0] ** 2 + arr[1] ** 2 == l ** 2: | |
print("right") | |
else: | |
print("wrong") |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10872번 팩토리얼 (C++, Python) (0) | 2022.04.09 |
---|---|
[백준 / BOJ] 3053번 택시 기하학 (C++, Python) (0) | 2022.04.09 |
[백준 / BOJ] 9020번 골드바흐의 추측 (C++, Python) (0) | 2022.04.08 |
[백준 / BOJ] 4948번 베르트랑 공준 (C++, Python) (0) | 2022.04.08 |
[백준 / BOJ] 1929번 소수 구하기 (C++, Python) (0) | 2022.04.06 |
@Reo :: 코드 아카이브
자기계발 블로그