<, > 에따라 올 수 있는지 없는지
쓴 알파벳인지 아닌지
최대, 최소
1~3기반으로 완탐을 한다.
시간복잡도는 10!이기 때문에.
이 세가지를 구현을 했지만 틀림...
"123", "124" 있을 때 "1"부터 아스키 코드값으로 비교를 한다.
문자열 대소비교할 때 size를 먼저 체크를 한다.
사이즈가 같은 것으로 비교를 해야한다.
atoi는 int로 atoll은 ll으로
'0'은 아스키 코드값으로 48이기 때문에 문자와 숫자를 비교하기 위해서 i + '0'을 해서 비교를 할 수 있게 하였다.
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define endl "\n"
#define ll long long
const ll INF = 1e18;
int n;
vector<string> ret;
int Check[10];
char a[10];
bool Good(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;
if (idx == 0 || Good(num[idx - 1], i + '0', a[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 >> a[i];
}
Go(0, "");
sort(ret.begin(), ret.end());
cout << ret[ret.size() - 1] << endl << ret[0] << endl;
return 0;
}