题解:P12860 [NERC 2020 Online] Kate' s 2021 Celebration
题意
Kate 在买气球,每个气球有自己的数字。Kate 喜欢包含 2 0 2 1 四个数字的气球(无论顺序)。现在她要找到最便宜的气球。
思路
模拟即可,使用字符串存储气球数字,然后用一个数组存储每个数字计算的次数,要是 2 出现的次数 0 出现的次数 1 出现的次数
记得给统计数组 cnt 重置。
代码
#include<bits/stdc++.h>
using namespace std;
long long n,a,price,ans=0,cnt[15]={};
string s;
int main()
{
cin>>n;
price=10000000;
for(int i=1;i<=n;++i)
{
cin>>a>>s;
for(int j=0;j<s.size();++j)
{
cnt[int(s[j])-int('0')]++;
}
if(cnt[2]>=2&&cnt[0]>=1&&cnt[1]>=1)
{
if(a<price)
{
ans=i;
price=a;
}
}
cnt[2]=0;
cnt[0]=0;
cnt[1]=0;
}
cout<<ans<<endl;
return 0;
}