char cMap[4][3] =
{
	'D','T','K',
	'E','A','P',
	'C','Q','G',
	'P','H','B'
};


int main()
{
	int ay, ax;
	int by, bx;
	for (int y = 0; y < 4; ++y)
	{
		for (int x = 0; x < 4; ++x)
		{
			if (cMap[y][x] == 'A')
			{
				ay = y; ax = x;
			}
			if (cMap[y][x] == 'B')
			{
				by = y; bx = x;
			}
		}
	}
	
	int ry = 0;
	if (by < ay) ry = ay - by;
	else ry = by - ay;

	int rx = 0;
	if (bx < ax) rx = ax - bx;
	else rx = bx - ax;

	cout << ry + rx;

	return 0;
}

 


int cMap[3][4] =
{
	3,4,1,5,
	3,4,1,3,
	5,2,3,6
};
int sum[4] = { 0 };

int main()
{
	for (int y = 0; y < 3; ++y)
	{
		for (int x = 0; x < 4; ++x)
		{
			sum[x] += cMap[y][x];
		}
	}
	
	int index = 0;
	cin >> index;

	cout << sum[index];
	return 0;
}

 


char str[100] = { 0 };
char tokens[2] = { 0 };
int idxs[4] = { 0 };

int main()
{
	cin >> str;
	cin >> tokens[0] >> tokens[1];
	int len = strlen(str);

	int lastIdx = 0;
	for (int i = 0; str[i] != '\0'; ++i)
	{
		if (str[i] == tokens[0] || str[i] == tokens[1])
		{
			idxs[lastIdx++] = i - 1;
			idxs[lastIdx++] = i + 1;
		}
	}

	for (int i = 0; i < 4; ++i)
	{
		if (idxs[i] < 0 || len <= idxs[i]) continue;
		str[idxs[i]] = '#';
	}

	cout << str;

	return 0;
}

 


char str[4][3] = {0};

int main()
{
	for (auto d : str)
	{
		cin >> d;
	}
	
	for (int x = 0; x < 3; ++x)
	{
		// 역순으로 순회
		for (int y = 3; -1 < y; --y)
		{
			// a. 문자를 찾지 못함
			if (str[y][x] == '_') continue;

			// b. 문자를 찾음
			int lastY = 4;
			do{
				--lastY;
			} while (y <= lastY && str[lastY][x] != '_');

			if (lastY < y) continue;

			str[lastY][x] = str[y][x];
			str[y][x] = '_';
		}
	}
    
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cout << str[i][j];
		}
		cout << endl;
	}

	return 0;
}

 


int bucket[10] = { 0 };

int main()
{
	for (int i = 0; i < 8; ++i)
	{
		int t; cin >> t;
		++bucket[t];
	}

	for (int i = 0; i < 10; ++i)
	{
		for (int j = 0; j < bucket[i]; ++j)
		{
			cout << i << " ";
		}
	}

	return 0;
}

 


 

int arr[4][3] = {
	1,5,3,
	4,5,5,
	3,3,5,
	4,6,2
};

int main()
{
	int a, b;
	cin >> a >> b;

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (a <= arr[i][j] && arr[i][j] <= b)
			{
				arr[i][j] = 0;
			}

			if (arr[i][j] == 0)
				cout << '#' << " ";
			else
				cout << arr[i][j] << " ";

		}
		cout << endl;
	}

	return 0;
}

 


 


struct S
{
	S() = default;
	S(char name, int y, int x)
		:Name(name), Y(y), X(x) {};

	char Name;
	int Y;
	int X;
};

// GLOBAL
S models[3];

char arr[5][3] = {
	'_','_','_',
	'_','_','_',
	'A','T','K',
	'_','_','_',
	'_','_','_',
};

bool DoCommand(char c, const char* str)
{
	// Find model what apply command
	S* target = nullptr;
	for (auto& d : models)
	{
		if (d.Name == c)
		{
			target = &d;
		}
	}

	// Apply command
	if (strcmp(str, "UP") == 0)
	{
		--(target->Y);
	}
	if (strcmp(str, "DOWN") == 0)
	{
		++(target->Y);
	}
	if (strcmp(str, "LEFT") == 0)
	{
		--(target->X);
	}
	if (strcmp(str, "RIGHT") == 0)
	{
		++(target->X);
	}

	return true;
}


int main() 
{
	// 1. Find modles
	int lastIdx = 0;
	for (int y = 0; y < 5; ++y)
	{
		for (int x = 0; x < 3; ++x)
		{
			if ('A' <= arr[y][x] && arr[y][x] <= 'Z')
			{
				models[lastIdx++] = S(arr[y][x], y, x);
				arr[y][x] = '_';
			}
		}
	}

	// 2. Apply command
	for (int i = 0; i < 7; ++i)
	{
		char target;
		char cmd[100] = { 0 };
		cin >> target >> cmd;

		DoCommand(target, cmd);
	}

	// 3. Replace modles
	for (int i = 0; i < 3; ++i)
	{
		arr[models[i].Y][models[i].X] = models[i].Name;
	}


	// Print
	for (int y = 0; y< 5; ++y)
	{
		for (int x = 0; x < 3; ++x)
		{
			cout << arr[y][x] << " ";
		}
		cout << endl;
	}

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV7] 복습 문제  (0) 2025.05.02
[LV7] 연습 문제  (0) 2025.04.29
[LV6] 연습 문제  (0) 2025.04.26
[LV5] 훈련 문제  (0) 2025.04.21
[LV5] 연습 문제  (0) 2025.04.21

+ Recent posts