组合数学。。。。和上一题是一样的。。。。
Word Index
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4303 Accepted: 2439

Description

Encoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with five or fewer (lower case) letters as integers.

Consider the English alphabet {a,b,c,...,z}. Using this alphabet, a set of valid words are to be formed that are in a strict lexicographic order. In this set of valid words, the successive letters of a word are in a strictly ascending order; that is, later letters in a valid word are always after previous letters with respect to their positions in the alphabet list {a,b,c,...,z}. For example,

abc aep gwz

are all valid three-letter words, whereas

aab are cat

are not.

For each valid word associate an integer which gives the position of the word in the alphabetized list of words. That is:

a -> 1
b -> 2
.
.
z -> 26
ab -> 27
ac -> 28
.
.
az -> 51
bc -> 52
.
.
vwxyz -> 83681
Your program is to read a series of input lines. Each input line will have a single word on it, that will be from one to five letters long. For each word read, if the word is invalid give the number 0. If the word read is valid, give the word's position index in the above alphabetical list. 

Input

The input consists of a series of single words, one per line. The words are at least one letter long and no more that five letters. Only the lower case alphabetic {a,b,...,z} characters will be used as input. The first letter of a word will appear as the first character on an input line.

The input will be terminated by end-of-file.

Output

The output is a single integer, greater than or equal to zero (0) and less than or equal 83681. The first digit of an output value should be the first character on a line. There is one line of output for each input line.

Sample Input

z
a
cat
vwxyz

Sample Output

26
1
0
83681

Source

East Central North America 1995

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int c[30][30];
char str[12];

void Init()
{
    for(int i=0;i<30;i++)
        c[0]=c=1;
    for(int i=2;i<30;i++)
        for(int j=1;j<i;j++)
            c[j]=c[i-1][j-1]+c[i-1][j];
}

int main()
{
    Init();
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        bool flag=true;
        for(int i=0;i<len-1;i++)
        {
            if(str>=str[i+1])
            {
                flag=false;
                break;
            }
        }
        if(flag==false)
        {
            puts("0");
            continue;
        }
        ///n-1...1
        int sum=0;
        for(int i=1;i<len;i++)
            sum+=c[26];
        ///n
        for(int i=0;i<len;i++)
        {
            char ch=(i==0)?'a':str[i-1]+1;
            while(ch<str)
            {
                sum+=c['z'-ch][len-1-i];
                ch++;
            }
        }
        printf("%d\n",++sum);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 1496 Word Index的更多相关文章

  1. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  2. 组合数学poj 1496 1850 同样的代码过两题

    Description   1942 Transmitting and memorizing information is a task that requires different coding ...

  3. poj 1850/poj 1496

    http://poj.org/problem?id=1850 -----------------http://poj.org/problem?id=1496 两题解法类似..本题为组合数学的题,要求所 ...

  4. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  5. poj 1204 Word Puzzles(字典树)

    题目链接:http://poj.org/problem?id=1204 思路分析:由于题目数据较弱,使用暴力搜索:对于所有查找的单词建立一棵字典树,在图中的每个坐标,往8个方向搜索查找即可: 需要注意 ...

  6. [POJ 1204]Word Puzzles(Trie树暴搜&amp;AC自己主动机)

    Description Word puzzles are usually simple and very entertaining for all ages. They are so entertai ...

  7. poj 1318 Word Amalgamation

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 ...

  8. POJ 1496

    #include <iostream> #include <string> using namespace std; int fac(int num); int C(int n ...

  9. poj1496 Word Index / poj1850 Code(组合数学)

    poj1850 Code 题意:输出若干个给定的字符串($length<=10$)在字典序中的位置,字符串中的字母必须严格递增. 读取到非法字符串时,输出“0”,终止程序.(poj1496:继续 ...

随机推荐

  1. 用python来调试网络程序

    需要联调的程序,沟通联调起来总是各种麻烦,如果自己能写个简单一点的“测试机”,事情就很easy了:或者有时候想做“中间人”,看看网路上到底传些什么.前面写了串口的测试机,今天尝试了一下UDP的. im ...

  2. centos卸载console-kit-da

    最近发现系统多出来 很多 console-kit-da 及它的子进程 占用了不少资源 which console-kit-da(很奇怪 为什么找不到执行文件) rpm -qa | grep -i co ...

  3. JSP+JavaBean+Servlet+Oracle新增功能中对Date类型的字段的处理

    Oracle库中userinfo表borth字段是Date类型,age年纪字段是int类型.age字段要根据borth来自动计算 先说一下我遇到的问题: insert into的时候遇到日期转换类型错 ...

  4. TortoiseSVN 过滤文件(包括已提交和未提交)

    一:svn 设置过滤文件方式 1.选中需要过滤的文件夹或者文件---右键---TortoiseSVN---Add to Ignore list(如果不显示说明该目录已经被添加) 2.在当前工作区域 不 ...

  5. mysql 某周的起始和结束日期

    转自:http://bbs.csdn.net/topics/370096126 t_table有数据如下:year    Week2011    22011    32011    42011     ...

  6. easyUI 树的上下文菜单

    一.属性:onContextMenu onContextMenu: function(e,node){ e.preventDefault(); $(this).tree('select',node.t ...

  7. 修改输入框placeholder文字默认颜色-webkit-input-placeholder

    html5为input添加了原生的占位符属性placeholder,高级浏览器都支持这个属性,例如: <input type="text" placeholder=" ...

  8. 网页js,DIV全屏布局

    <script type="text/javascript"> $(document).ready(function(){ findDimensions(); }); ...

  9. Effective Objective-C 2.0 — 第二章 对象、消息、运行期 - 第六条:理解“属性”这一概念

    开发者通过对象来 存储并传递数据. 在对象之间传递数据并执行任务的过程就叫做“消息传递”. 这两条特性的工作原理? Objective-C运行期环境(Objective-C runtime) ,提供了 ...

  10. json_decode

    <?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}' ...