zoukankan      html  css  js  c++  java
  • Code--POJ1850

    Description

    Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is that one where a number is associated to a character sequence. It is considered that the words are made only of small characters of the English alphabet a,b,c, ..., z (26 characters). From all these words we consider only those whose letters are in lexigraphical order (each character is smaller than the next character).
    The coding system works like this:
    • The words are arranged in the increasing order of their length. • The words with the same length are arranged in lexicographical order (the order from the dictionary). • We codify these words by their numbering, starting with a, as follows:
    a - 1
    b - 2
    ...
    z - 26
    ab - 27
    ...
    az - 51
    bc - 52
    ...
    vwxyz - 83681
    ...
    Specify for a given word if it can be codified according to this coding system. For the affirmative case specify its code.

    Input

    The only line contains a word. There are some constraints: • The word is maximum 10 letters length • The English alphabet has 26 characters.

    Output

    The output will contain the code of the given word, or 0 if the word can not be codified.

    Sample Input

    bf

    Sample Output

    55


    题意显而易见;看代码吧

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    #define maxn 30
    
    int main()
    {
        long long i, j, k, a[maxn][maxn]={0}, b[maxn]={0,26};//a[3][2]代表长度3(i),以b(j)开头的的有多少个
        char s[20];
    
        for(i=1; i<=26; i++)
            a[1][i] = 1;
    
        for(i=2; i<=26; i++)
        {
            for(j=1; j<=26; j++)
            {
                for(k=j+1; k<=26; k++)
                    a[i][j] += a[i-1][k];
                b[i] += a[i][j];
            }
        }
    
        while(scanf("%s", s) != EOF)
        {
            int len = strlen(s), ok=0;
            long long sum = 0;
    
            for(i=1; i<len; i++)
                sum += b[i];
    
            for(i=1;i<s[0]-'a'+1;i++)
                sum+=a[len][i];
            len--;
            for(i=1; s[i]; i++)
            {
                if( s[i] <= s[i-1])
                    ok = 1;
                for(j=s[i-1]-'a'+2;j<s[i]-'a'+1;j++)
                {
                    sum+=a[len][j];
                }
                len--;
            }
    
            if(ok)
                printf("0
    ");
            else
                printf("%lld
    ", sum+1);
        }
    
        return 0;
    }
  • 相关阅读:
    在spring官网上下载历史版本的spring插件,springsource-tool-suite
    转载---VB DorpDownList控件 添加选项
    VB,将"秒"转成"时分秒"格式
    VB.NET 改变datatable数据类型
    转载--- C# 图片与base64编码 互相转换
    转载--- php5.6:Call to undefined function curl_init()的解决办法
    转载--- navicat12破解版(英文、中文)
    转载---mysql导出事件、存储过程、函数、库表
    C# 读取mysql blob字段(两种方式)
    转载---安装mysql5.7,遇到的问题
  • 原文地址:https://www.cnblogs.com/zhengguiping--9876/p/4466980.html
Copyright © 2011-2022 走看看