#include<stdio.h> int cnt[10]; int main() { int n=2021,i,x,k=1; for(i=0;i<10;i++)cnt[i]=n; while(1){ x=k; while(x){ if(cnt[x%10]>0)cnt[x%10]--,x/=10; else break; } if(x)break; else k++; } printf("%d",k-1); return 0; }
python
cards = [2021] * 10 # 检查当前的数字n是否是拼出来 def check(n: int): while n: t = n % 10 if cards[t] - 1 < 0: return False cards[t] -= 1 n //= 10 return True if __name__ == '__main__': i = 1 while True: if check(i): i += 1 else: print(i - 1) break