这道题要求我们找出最小满足要求的字符串,我们需要判断每个数字出现多少次,可以使用数位分离法,开变量记录即可。
#include<bits/stdc++.h>
using namespace std;
int n,h=1,t,ans=INT_MAX,k;
string s;
int main(){
cin>>n;
while(h<=n){
cin>>t>>s;
int a=0,b=0,c=0;
for(int i=0;i<s.size();i++){
if(s[i]=='2') a++;
if(s[i]=='0') b++;
if(s[i]=='1') c++;
}
if(a>=2&&b>=1&&c>=1){
if(t<=ans) k=h,ans=t;
}
h++;
}
cout<<k;
return 0;
}