• 牛客练习赛53 C 富豪凯匹配串


    思路:

    bitset的简单题,不幸的是当时的我并不知道bitset,

    C++的 bitset 在 bitset 头文件中,它是一种类似数组的结构,它的每一个元素只能是0或1,每个元素仅用1bit空间,省时省空间!

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<bitset>
    #include<string>
    using namespace std;
    typedef bitset<1000> BIT;//typedef 不能少,作用:为复杂的声明定义简单的别名 
    BIT bit1[1005],bit2,bit3;
    string str,str1;
    int n,m,q;
    int main(){
        cin>>n>>m; 
        for(int i = 1;i<=n;i++){
            cin>>str;
            bit1[i] = BIT(str);
        } 
        cin>>q;
        for(int i = 1;i<=q;i++){
            cin>>str;
            str1 = str;
            int j;
            for(j = 0;j<m;j++){
                if(str[j]=='_')
                    str1[j] = str[j] = '0';
                else
                    str1[j] = '1'; 
            }
            str1[j] ='';
            bit2 = BIT(str1);
            bit3 = BIT(str);
            int ans = 0;
            for(j = 1;j<=n;j++){
                if((bit1[j]&bit2)==bit3)
                    ans++;
            }
            cout<<ans<<endl;
        }
        
        return 0;
    }
  • 相关阅读:
    【bozj2287】【[POJ Challenge]消失之物】维护多值递推
    书籍
    图书管理系统-单表的增删改查
    Django之ORM
    app的创建和注册
    登陆示例
    django 静态文件配置
    安装django及配置
    Bootstrap
    导图
  • 原文地址:https://www.cnblogs.com/lusiqi/p/11715491.html
Copyright © 2020-2023  润新知