백준 2529 부등호 (다시분석)

CJB_ny·2023년 2월 26일
0

백준

목록 보기
90/104
post-thumbnail

부등호


이전에 어디가 예외사항인줄 몰라서 질문을 올렸었는데

이전에 질문한코드

알아야할 점이 정수랑 문자랑 비교하기위해서

정수 + '0'을해서 아스키 코드값 맞춰버림.

cpp 코드

#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX 20
#define endl "\n"

int n, Check[10];
char arr[MAX];
vector<string> ret;

bool Cango(char x, char y, char op)
{
	if (x < y && op == '<') return true;
	if (x > y && op == '>') return true;
	return false;
}

void Go(int idx, string num)
{
	if (idx == n + 1)
	{
		ret.push_back(num); return;
	}
	for (int i = 0; i <= 9; ++i)
	{
		if (Check[i]) continue;

		// 정수랑 문자랑 맞추기위해서 i + '0'
		if (idx == 0 || Cango(num[idx - 1], i + '0', arr[idx - 1]))
		{
			Check[i] = 1;
			Go(idx + 1, num + to_string(i));
			Check[i] = 0;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i) cin >> arr[i];

	Go(0, "");
	sort(ret.begin(), ret.end());
	cout << ret[ret.size() - 1] << endl << ret[0] << endl;
	
	return 0;
}
profile
https://cjbworld.tistory.com/ <- 이사중

0개의 댓글