博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1496 Word Index
阅读量:5034 次
发布时间:2019-06-12

本文共 3102 字,大约阅读时间需要 10 分钟。

Word Index

Time Limit: 1000MS

Memory Limit:10000K

Total Submissions: 3586

Accepted:2030

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

zacatvwxyz

Sample Output

261083681
 
1: #include 
2: using namespace std;
3:
4: __int64 dp[16][32], sum[16], ans;
5:
6: int main()
7: {
8:     int i, j, len;
9:     char str[16];
10:
11:     for (i = 0; i < 26; i++)
12:         dp[0][i] = 1;
13:     for (i = 1; i < 10; i++) {
14:         for (j = 25 - i; j >= 0; j--) {
15:             dp[i][j] += dp[i][j + 1];
16:             dp[i][j] += dp[i - 1][j + 1];
17:         }
18:     }
19:     for (i = 0; i < 10; i++)
20:         for (j = 0; j < 26; j++)
21:             sum[i] += dp[i][j];
22:
23: 	while(scanf("%s", str)!=EOF)
24: 	{
25: 		ans=0;
26: 	    for (len = 0; str[len]; len++)
27: 	        ans += sum[len];
28: 	    ans -= sum[len - 1];
29: 	    j = 0;
30: 	    for (i = len - 1; i >= 0; i--) {
31: 	        while (j < str[len - 1 - i] - 'a') {
32: 	            ans += dp[i][j];
33: 	            j++;
34: 	        }
35: 	        j++;
36: 	    }
37: 	    for (i = 0; i < len - 1; i++)
38: 	        if (str[i] >= str[i + 1])
39: 	            ans = -1;
40: 	    printf("%I64d\n", ans + 1);
41: 	}
42:     return 0;
43: }
44:
45:

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/21/2257575.html

你可能感兴趣的文章
【HNOI2015】菜肴制作
查看>>
javascript继承
查看>>
海思uboot启动流程详细分析(三)【转】
查看>>
sitemesh2.x+velocity+springmvc乱码解决方案
查看>>
Python面向对象03/继承
查看>>
java序列化和反序列化
查看>>
绝对定位
查看>>
flink源码编译(windows环境)
查看>>
dpkg 删除 百度网盘 程序
查看>>
服务器nginx安装
查看>>
std::nothrow
查看>>
rest-framework 分页器
查看>>
JQuery(一)安装&选择器 样式篇
查看>>
浏览器的DNS缓存查看和清除
查看>>
浏览器跨域问题
查看>>
HTML5 input控件 placeholder属性
查看>>
使用JAVA如何对图片进行格式检查以及安全检查处理
查看>>
html5实现移动端下拉刷新(原理和代码)
查看>>
iPhone开发中从一个视图跳到另一个视图有三种方法:
查看>>
pytho logging
查看>>