반응형
중첩 for문을 사용해 모든 경우의수를 전부 대입
// Preset 생략
vector<int> ables;
int n;
int stx = 0, sty = 0, stz = 0, sta = 0, stb = 0, stc = 0;
set<int> used;
bool included(int x)
{
for (int y : ables)
if (x == y)
return true;
return false;
}
bool allIncluded(int x)
{
while (x)
{
if (!included(x % 10))
return false;
x /= 10;
}
return true;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
ables.push_back(x);
}
for (int a : ables)
for (int b : ables)
for (int c : ables)
{
stx = 100 * a + 10 * b + c;
if (stx < 100)
continue;
if (stx > 999)
continue;
for (int d : ables)
{
sty = stx * d;
if (sty > 999)
continue;
if (!allIncluded(sty))
continue;
for (int h : ables)
{
sta = stx * h;
if (sta > 999)
continue;
if (!allIncluded(sta))
continue;
stb = sty + sta * 10;
if (!allIncluded(stb))
continue;
stz = stx * 1000 + d * 10 + h;
if (used.find(stz) != used.end())
continue;
used.insert(stz);
stc++;
}
}
}
cout << stc;
}
반응형