본문 바로가기

백준/C++

[Baekjoon/C++] 21875번 - Innohorse

[백준] 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;
}

 두 좌표의 가로, 세로 거리를 계산한 다음 작은 것부터 출력하면 된다.