CodeForces-Vanya and Label

本文介绍了一种通过位运算计算特定字符串与另一未知字符串按位与等于原字符串的可能组合数量的方法。通过预设字符与对应的数值关系,利用位运算统计不同字符组合的可能性。

题意:输入一串字符s,每个字符对应一个数字,求这个字符串&另一个字符串等于s本身的数量,字符s和满足要求的另一个字符在&前后位置算两种。

思路:看官方题解的

#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<iostream>
#define FIN freopen("input.txt","r",stdin)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
string s;
string index;
ll symbol_num[305];
int main()
{
    for(char i='0'; i<='9'; i++)
        index.push_back(i);
    for(char i='A'; i<='Z'; i++)
        index.push_back(i);
    for(char i='a'; i<='z'; i++)
        index.push_back(i);
    index.push_back('-');
    index.push_back('_');
    for(int i=0; i<64; i++)
    {
        symbol_num[index[i]]=i;
    }
    //FIN;
    while(cin>>s)
    {
        ll ans=1;
        for(int i=0; i<s.size(); i++)
        {
            ll x=symbol_num[s[i]];
            for(int j=0; j<6; j++)
                if((x&(1<<j))==0) ans=(ans*3)%MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值