[백준] Baekjoon Online Judge
문제
In Innokingdom there are special horses for chess knights, innohorses. Each innohorse is represented by a pair of integers , 0≤x≤y. Innohorse moves in the following way: first it moves x cells in one of the four general directions, then turns 90 degrees to the left or to the right, then finally moves y more cells. For instance, an ordinary chess knight horse is an innohorse of type .
Alex and Jane has just seen one innohorse, it jumped from cell A to cell B. They wonder what is the type of this innohorse. Help them answer this question.
입력
Chessboard consists of 8 rows and 8 columns. Rows are assigned integers from 1 to 8, and columns are assigned letters from 'a' to 'h'. So every cell is represented by a pair of a letter and a digit.
Two lines consist of descriptions of cells A and B respectively.
출력
Print two integers x and y (0≤x≤y), representing the type of innohorse.
풀이
#include <iostream>
#include <cmath>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string A, B;
cin >> A >> B;
int n = abs(A[0] - B[0]);
int m = abs(A[1] - B[1]);
cout << min(n, m) << ' ' << max(n, m) << '\n';
return 0;
}
두 좌표의 가로, 세로 거리를 계산한 다음 작은 것부터 출력하면 된다.
'백준 > C++' 카테고리의 다른 글
[Baekjoon/C++] 2490번 - 윷놀이 (0) | 2025.03.11 |
---|---|
[Baekjoon/C++] 3190번 - 뱀 (0) | 2025.02.25 |
[Baekjoon/C++] 14499번 - 주사위 굴리기 (0) | 2025.02.23 |
[Baekjoon/C++] 2357번 - 최솟값과 최댓값 (0) | 2025.02.14 |
[Baekjoon/C++] 1202번 - 보석 도둑 (0) | 2025.02.12 |