Cattle-off practice match 53 C title bitset

Topic Linkhttps://ac.nowcoder.com/acm/contest/1114/C

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const int p=1e9+7;
const int N=1010;
bitset<N>a[N],t,q;//t是模式串,q是目标串 
char s[N];
int main()
{
    int n,m,T;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        for(int j=0;j<m;j++)
        {
            a[i][j]=(s[j]=='1');
         } 
    }
    cin>>T;
    while(T--)
    {
        scanf("%s",s);
        for(int i=0;i<m;i++)
        {
            if(s[i]=='_')
            {
                t[i]=0;
                q[i]=0;
            }
            else
            {
                q[i]=(s[i]=='1');
                t[i]=1;
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if((a[i]&t)==q)
                ans++;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hh13579/p/11665441.html