zoukankan      html  css  js  c++  java
  • CSU

    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
    Hint
    The vowel means ‘A’,’E’,’I’,’O’,’U’

    The consonant means the other 21 letter.

    The special tragedy letter ‘L’ still belongs to consonant.

    Of course, the letter here means English letters, not other language letters.

    题意:一个单词长度不超过100,有最多10个空格,现在要在空格中填入字母来构造单词,使得单词符合“悲伤单词”的条件。
    条件1:不能连续出现三个元音字母或辅音字母
    条件2:单词必须带有字母L
    条件3:全部为大写字母
    问有多少种填写方法使得单词是“悲伤”单词

    因空格数量不多,直接暴力枚举每个空格可以填入的字母,然后判断是否符合条件。
    对于单词中的字母,我们可以抽象为3类,元音字母,辅音字母,字母L
    分别在空格中填入这3类字母,填入元音字母有5中情况,填入辅音字母有20种情况(除去字母L),填入字母L有一种情况。
    对于这样一个构造出来的单词,最后直接遍历填入类型加和到答案中。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<vector>
    #define LL long long
    using namespace std;
    const int maxn=108;
    LL ans;
    char aa[maxn];
    int n,len;
    vector<int>q;
    void dfs(int x,char tmp[],bool flag)
    {
        char a[maxn];
        strcpy(a,tmp);
        if(x==len)
        {
            if(a[x-3]=='A'&&a[x-2]=='A'&&a[x-1]=='A')return;
            if(x>2&&a[x-3]!='A'&&a[x-2]!='A'&&a[x-1]!='A')return;
            if(flag)
            {
    //            printf("------%s
    ",a);
                LL sum=1;
                for(int i=0; i<q.size(); i++)
                {
                    if(a[q[i]]=='A')sum*=5ll;
                    else if(a[q[i]]=='B')sum*=20ll;
                }
                ans+=sum;
            }
            return;
        }
        if(aa[x]=='_'&&x>=2)
        {
            q.push_back(x);
            if(a[x-1]!='A'||a[x-2]!='A')
            {
                a[x]='A';
                dfs(x+1,a,flag);
            }
            if(a[x-1]=='A'||a[x-2]=='A')
            {
                a[x]='B';
                dfs(x+1,a,flag);
                a[x]='L';
                flag=true;
                dfs(x+1,a,flag);
            }
            q.pop_back();
        }
        else if(aa[x]=='_'&&x<2)
        {
            q.push_back(x);
            a[x]='A';
            dfs(x+1,a,flag);
            a[x]='B';
            dfs(x+1,a,flag);
            a[x]='L';
            flag=true;
            dfs(x+1,a,flag);
            q.pop_back();
        }
        else
        {
            if(a[x-2]=='A'&&a[x-1]=='A'&&a[x]=='A')return;
            if(x>1&&a[x-2]!='A'&&a[x-1]!='A'&&a[x]!='A')return;
            if(a[x]=='L')flag=true;
            dfs(x+1,a,flag);
        }
    }
    int main()
    {
        while(scanf("%s",&aa)!=EOF)
        {
            len=strlen(aa);
            ans=0;
            for(int i=0; i<len; i++)
            {
                if(aa[i]=='A'||aa[i]=='E'||aa[i]=='I'||aa[i]=='O'||aa[i]=='U')aa[i]='A';
                else if(aa[i]!='_'&&aa[i]!='L')aa[i]='B';
            }
            q.clear();
            dfs(0,aa,false);
            printf("%lld
    ",ans);
        }
    }
    
  • 相关阅读:
    如果把表单数据的校验交给了javascript那么后台还有没有必要对数据做校验呢
    JSR303注解
    C++ STL标准模板库(stack)
    C++ STL标准模板库(vector)
    C++ 类模板三(类模版中的static关键字)
    C++ 类模板二(类模版与友元函数)
    C++ 类模板一(类模板的定义)
    C语言 百炼成钢27
    C语言 百炼成钢26
    C语言 百炼成钢25
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11135744.html
Copyright © 2011-2022 走看看