博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SCAU 2006校赛 6582 Encode
阅读量:5947 次
发布时间:2019-06-19

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

6582 Encode

时间限制:753MS  内存限制:1000K 提交次数:48 通过次数:25

题型: 编程题   语言: 无限制

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.

输入格式

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.

输出格式

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.

输入样例

zacatvwxyz

输出样例

261083681

作者

admin

#include
#include
int main(){ int len, i, j, sum, ans, flag, a1, a2, a3, a4, a5, t, temp1, temp2, temp3, temp4; char word[8]; int base[4];//保存长度分别为1,2,3,4 时的最后一串字符所代表的值,即z, yz, xyz, wxyz,为了方便下一长度的字符串调用 memset(base, 0, sizeof(base)); base[0] = 26; base[1] = base[0] + (25+1)*25/2; for(i=24; i>=1; --i) base[2] += (1+i)*i/2; base[2] += base[1]; for(i=23; i>=1; --i) { base[3] += (24-i)*(i+1)*i/2; } base[3] += base[2]; while(scanf("%s", word) != EOF) { len = strlen(word); for(i=0,flag=0; i
=1; --j) sum += (j+1)*j/2; } temp1 = 23 - a1; a2 = word[1] - 'a' - a1; for(i=1; i<=a2-1; ++i) sum += (temp1+1-i+1)*(temp1+1-i)/2; a3 = word[2] - 'a' - (word[1] - 'a'); temp2 = temp1 - a2 + 1; for(i=0; i
=1; --j) sum += (24-i-j)*(j+1)*j/2; } temp1 = 22 - a1; a2 = word[1] - 'a' - a1 - 1; for(i=1; i<=a2; ++i) for(j=temp1+1-i; j>=1; --j) sum += (j+1)*j/2; a3 = word[2] - 'a' - (word[1] - 'a'); temp2 = temp1 - a2; for(i=1; i<=a3-1; ++i) sum += (temp2+1-i+1)*(temp2+1-i)/2; a4 = word[3] - 'a' - (word[2] - 'a') - 1; temp3 = temp2 - a3 + 1; for(i=0; i

转载于:https://www.cnblogs.com/liaoguifa/archive/2013/03/31/2991527.html

你可能感兴趣的文章
微服务+:服务契约治理
查看>>
save
查看>>
Android DrawLayout + ListView 的使用(一)
查看>>
clear session on close of browser jsp
查看>>
关于吃掉物理的二次聚合无法实现的需要之旁门左道实现法
查看>>
mysql出现unblock with 'mysqladmin flush-hosts'
查看>>
oracle exp/imp命令详解
查看>>
开发安全的 API 所需要核对的清单
查看>>
Mycat源码中的单例模式
查看>>
WPF Dispatcher介绍
查看>>
fiddler展示serverIP方法
查看>>
已释放的栈内存
查看>>
Android网络之数据解析----SAX方式解析XML数据
查看>>
Java递归列出所有文件和文件夹
查看>>
[关于SQL]查询成绩都大于80分的学生
查看>>
Delphi(Tuxedo,BDE,ADO)三合一数据集组件HsTxQuery
查看>>
LeetCode - Longest Common Prefix
查看>>
Android图片处理
查看>>
2015年第21本:万万没想到,用理工科思维理解世界
查看>>
大家谈谈公司里的项目经理角色及职责都是干什么的?
查看>>