Tragedy Words

As is known to all, Wells doesn't have a good command of English. As a result, some unfamiliar words, which may cause sadness of Wells, is called tragedy words. In more detail, a word will be defined as a tragedy word, if and only if when it satisfies all following conditions. 

First, it only contain uppercase letter.

Second, it doesn't contain three consecutive vowel(AEIOU) or three consecutive consonant(the other 21 letter).

And last of all, it should contain at least one special tragedy letter 'L'.

Now, you are given a word, which consists of uppercase letter or underline, and you are allow to fill each underline with one uppercase letter. And in order to make fun of Wells, you want to know how many tragedy words you can make in this way.

Input

For each test, only contains a line of one word, which consists of uppercase letter and underline(’_’).

The total length of each word will not exceed 100, and the number of underline(’_’) will not exceed 10.

Output

For each test, print one line, which contains a integer as the total amount of tragedy words you can make.

Notice: the number may be very large and may exceed the 32-bits unsigned integer.

Sample Input

V__K
V_K

Sample Output

10
0

//题目大意:给你包涵'_'的字符串,可以给'_'填上'A'-'Z'的字母,填完后,要求字符串中必须有'L',要求字符串中不能出现连续的3个元音字母或3个连续的辅音字母,求共有几种填法;

//思路:将字符串中的元音字母看做1,辅音字母看做2,dfs得到总的填法,然后减去不含'L'的填法;

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
int a[110];
char s[110];
int b[110];
int flag=0;
int len;
int sizee;
ll ans=0;
ll num1=1;
ll num2=1;
void dfs(int k)
{
    if(k==sizee)
    {
        if(flag==1)
        {
            ans+=num1;
        }
        else
        {
            ans+=num1-num2;
        }
        return ;
    }
    int id=a[k];
    b[id]=1;num1*=5;num2*=5;
    if((b[id]==1&&b[id-1]==1&&b[id-2]==1&&id-2>=0)||(b[id]==1&&b[id+1]==1&&b[id+2]==1&&id+2<=len-1)
       ||(id-1>=0&&id+1<=len-1&&b[id-1]==1&&b[id]==1&&b[id+1]==1))
    {
        b[id]=0;num1/=5;num2/=5;
    }else
    {
        dfs(k+1);
        b[id]=0;num1/=5;num2/=5;
    }
    b[id]=2;num1*=21;num2*=20;
    if((b[id]==2&&b[id-1]==2&&b[id-2]==2&&id-2>=0)||(b[id]==2&&b[id+1]==2&&b[id+2]==2&&id+2<=len-1)
       ||(id-1>=0&&id+1<=len-1&&b[id-1]==2&&b[id]==2&&b[id+1]==2))
    {
        b[id]=0;num1/=21;num2/=20;
    }else
    {
        dfs(k+1);
        b[id]=0;num1/=21;num2/=20;
    }
    return ;
}
int check(char a)
{
    if(a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
        return 1;
    else
        return 0;
}
int main()
{
    while(~scanf("%s",s))
    {
        len=strlen(s);
        flag=0;
        sizee=0;
        for(int i=0;i<len;i++)
        {
            if(s[i]=='L')flag=1;
            if(s[i]=='_'){a[sizee++]=i;b[i]=0;}
            else if(check(s[i])==1)b[i]=1;
            else if(check(s[i])==0)b[i]=2;
        }
        ans=0;
        num1=num2=1;
        dfs(0);
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37378303/article/details/81779837
今日推荐