#C++初学记录(ACM8-6-cf-f题)

Posted xiaofengqaq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#C++初学记录(ACM8-6-cf-f题)相关的知识,希望对你有一定的参考价值。

F. Vanya and Label


While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 1e9?+?7.

To represent the string as a number in numeral system with base 64 Vanya uses the following rules:
digits from ‘0‘ to ‘9‘ correspond to integers from 0 to 9;
letters from ‘A‘ to ‘Z‘ correspond to integers from 10 to 35;
letters from ‘a‘ to ‘z‘ correspond to integers from 36 to 61;
letter ‘-‘ correspond to integer 62;
letter ‘_‘ correspond to integer 63;


Input

The only line of the input contains a single word s (1?≤?|s|?≤?100?000), consisting of digits, lowercase and uppercase English letters, characters ‘-‘ and ‘_‘.

Output

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 1e9?+?7.


Examples
input


z

output

3

input

V_V

output
9

input

Codeforces

output

130653412

Note

For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.

In the first sample, there are 3 possible solutions:


z&?=?61&63?=?61?=?z
&z?=?63&61?=?61?=?z
z&z?=?61&61?=?61?=?z

正确代码

#include<bits/stdc++.h>
using namespace std;
#define modd 1000000007
int main()
    char a[100006];
    cin>>a;
    long long lena=strlen(a);
    long long ans=1;
    long long n;
    for(int i=0;i<lena;i++)
        
        n=0;
        
        if(a[i]>='0'&&a[i]<='9')
        n=a[i]-'0';
        
        if(a[i]>='A'&&a[i]<='Z')
        n=a[i]-'A'+10;
        
        if(a[i]>='a'&&a[i]<='z') 
        n=a[i]-'a'+36;
        
        if(a[i]=='-')
        n=62;
        
        if(a[i]=='_') 
        n=63;
        
        for(int j=0;j<6;j++)
            if(((n>>j)&1)==0)
                ans=(ans*3)%modd;
            
        
    
    cout<<ans<<endl;
    return 0;
 

题目理解

给出一个字符串,字符串中可能含有1-9的数字,a-z的字母,A-Z的字母,然后将他们全部转化成题目给出的编码,得到编码后,通过程序进行判断有多少个字符组合通过AND(&)符运算后不会改变字符串中字符的编码。

相关知识点
本题完成需要读懂题目,判断字符串中编码不仅仅是将其化为ascll码,而是要根据题意进行初始编码后再进行化为二进制,其次二进制的判断是位移运算符与AND运算符结合完成的,具体代码为


        for(int j=0;j<6;j++)
            if(((n>>j)&1)==0)
                ans=(ans*3)%modd;
            
        

由题意得出最大代码为63的“_”,即不超过64位,因此二进制可以化为六位数正好小于2^6,到此代码编写与理解完成。

以上是关于#C++初学记录(ACM8-6-cf-f题)的主要内容,如果未能解决你的问题,请参考以下文章

#C++初学记录(STL容器以及迭代器)

#C语言初学记录(位运算)

Java初学记录——初识

Java初学记录——初识

Java初学记录——初识

一道在Oracle中建表的sql题 我是初学者 谢谢

(c)2006-2024 SYSTEM All Rights Reserved IT常识