蓝桥杯2021C++B组第二题,大家看看

题目:

img

结果:不对

img

#include <iostream>
using namespace std;
int s[10];
 bool check(int x){
     while(x)
     {
         int t=x%10;
           x/=10;
           if(--s[t]<0) return false;
     }
     return true;
 }
int main()
{
   for(int i=0;i<10;i++) s[i]=2021;
    for(int i=1;;i++)
        {
       if(!check[i])
       {

        cout<<i-1;
       return 0;
        }
         }
   return 0;
}



#include<bits/stdc++.h>
using namespace std;//答案:3181 
int use[20]={2021,2021,2021,2021,2021,2021,2021,2021,2021,2021}; 
int jud(){
    for(int i=0;i<=9;i++){
        if(use[i]==0){
            return 1;
        }
    }
    return 0;
}
int main(){
    int a,b,c,d,i;
    for(i=1;i<10000;i++){//当已使用完则跳出循环 
        a=i/1000,b=(i/100)%10,c=(i/10)%10,d=i%10;
        if(i<10){
            use[d]--;
        }
        else if(i<100){
            use[c]--;
            use[d]--;
        }
        else if(i<1000){
            use[b]--;
            use[c]--;
            use[d]--;
        }
        else if(i<10000){
            use[a]--;
            use[b]--;
            use[c]--;
            use[d]--;
        }
        if(jud()){
            break; 
        }
    }
    cout<<i;
    return 0;
} 


#include<iostream>
#include <unordered_map>
using namespace std;
int main()
{
    unordered_map<int, int> map;
    int i = 1;
    for (;;i++) {
        int t = i;
        bool b = false;
        while (t) 
        {
            map[t % 10]++;
            if (map[t % 10] > 3)
            {
                b = true;
                break;
            }
            t = t / 10;
        }
        if (b)
            break;
        
    }
    cout << i << endl;
    return 0;
}