随笔
这个很简单就是要注意0的处理,忘了这个0的情况卡了我好长时间贴一份代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
char s[11];
int a[11];
signed main(){
int n,d;
cin>>n>>d;
string k;
cin>>k;
for(int i=0;i<n;i++){
char c;
c=k[i];
a[c-'0']++;
}
if(a[0]){cout<<0;return 0;}
for(int i=1;i<=1e8;i++){
int t=i*d;
int g[10]={0};
bool f=true;
while(t){
g[t%10]++;
if(g[t%10]>a[t%10]){f=false;t=0;}
t/=10;
}
if(f){cout<<i*d;return 0;}
}
cout<<-1;
}
查看15道真题和解析
小天才公司福利 1166人发布