题目
代码
#include <bits/stdc++.h>
using namespace std;
int cnt[10];
bool consume(int x)
{
int need[10] = {0};
while (x)
{
int k = x % 10;
need[k]++;
x /= 10;
}
for (int i = 0; i < 10; i++)
{
if (cnt[i] < need[i])
return false;
}
for (int i = 0; i < 10; i++)
{
cnt[i] -= need[i];
}
return true;
}
int main()
{
int i;
for (i = 0; i < 10; i++)
cnt[i] = 2021;
for (i = 1; i <= 1e9; i++)
{
if (!consume(i))
break;
}
cout << --i;
}