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]={}, b[maxn]={,};//a[3][2]代表长度3(i),以b(j)开头的的有多少个
char s[]; for(i=; i<=; i++)
a[][i] = ; for(i=; i<=; i++)
{
for(j=; j<=; j++)
{
for(k=j+; k<=; k++)
a[i][j] += a[i-][k];
b[i] += a[i][j];
}
} while(scanf("%s", s) != EOF)
{
int len = strlen(s), ok=;
long long sum = ; for(i=; i<len; i++)
sum += b[i]; for(i=;i<s[]-'a'+;i++)
sum+=a[len][i];
len--;
for(i=; s[i]; i++)
{
if( s[i] <= s[i-])
ok = ;
for(j=s[i-]-'a'+;j<s[i]-'a'+;j++)
{
sum+=a[len][j];
}
len--;
} if(ok)
printf("0\n");
else
printf("%lld\n", sum+);
} return ;
}

Code--POJ1850的更多相关文章

  1. poj1850 Code【组合数学】By cellur925

    题意: * 按照字典序的顺序从小写字母 a 开始按顺序给出序列 (序列中都为升序字符串)* a - 1* b - 2* ...* z - 26* ab - 27* ...* az - 51* bc - ...

  2. POJ1850——Code(组合数学)

    Code DescriptionTransmitting and memorizing information is a task that requires different coding sys ...

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

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

  4. poj1850 Code

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10059   Accepted: 4816 Description ...

  5. POJ1850 Code(组合+康托展开)

    题目问一个合法字符串的字典序是第几个,合法的字符串是指里面的字符严格递增. 先判断合不合法,然后用类似康托展开的过程去求.大概过程就是用组合数算出某长度某前缀有几个,累加起来. 真难一遍写对.. #i ...

  6. 【poj1850】 Code 数位dp+记忆化搜索

    题目大意:给你一个字符串,问你这个字符串的rank,如果这个字符串不合法,请直接输出0.(一个合法的字符串是对于∀i,有c[i]<c[i+1]) 字符串s的rank的计算方式:以字符串长度作为第 ...

  7. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  8. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  9. Code Review 程序员的寄望与哀伤

    一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...

  10. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

随机推荐

  1. 给sharepoint某列表项单独赋予权限

    /// <summary> /// 列表项事件 /// </summary> public class EventReceiver2 : SPItemEventReceiver ...

  2. ConcurrentModificationException 详解

    工作中碰到个ConcurrentModificationException.代码如下: List list = ...;for(Iterator iter = list.iterator(); ite ...

  3. java接口定义的静态方法和默认如何在类实现的时候使用

    在 JDK1.8,允许我们给接口添加两种非抽象的方法实现: 1.默认方法,添加 default 修饰即可: 2.静态方法,使用 static 修饰:示例如下: 这样可以实现接口的增强,那我们在类实现接 ...

  4. 《转载》图解Tomcat类加载机制

    本文转载自http://www.cnblogs.com/xing901022/p/4574961.html 说到本篇的tomcat类加载机制,不得不说翻译学习tomcat的初衷. 之前实习的时候学习j ...

  5. open-falcon之HBS

    功能 处理agent心跳请求,并将agent信息(ip.hostname.agent_version.plugin_version)等信息入库(portal库) 为agent提供执行run api的白 ...

  6. 【vue基础学习】vue.js开发环境搭建

    1.安装node.js(http://www.runoob.com/nodejs/nodejs-install-setup.html) 2.基于node.js,利用淘宝npm镜像安装相关依赖 在cmd ...

  7. jQuery Sizzle选择器(一)

    1.浏览器对css选择器采取逆向(从右向左)解析的原因: 如果正向解析,例如「div div p em」,我们首先就要检查当前元素到 html 的整条路径,找到最上层的div,再往下找,如果遇到不匹配 ...

  8. Android 4.0的图形硬件加速及绘制技巧

    转:http://zuiniuwang.blog.51cto.com/3709988/721798 从Android 3.0开始,Android 2D的绘制流程就设计为能够更好地支持硬件加速.使用GP ...

  9. sencha touch 在安卓中横屏、竖屏切换 应用崩溃问题

    答案来至于 Sencha Touch 交流 @周旭 这是由于横竖屏转换导致activity重跑onCreate方法导致的,有两种解决方案:1.横竖屏转换的时候不要重新跑onCreate方法,这个可以在 ...

  10. spring应用中多次读取http post方法中的流(附源码)

    一.问题简述 先说下为啥有这个需求,在基于spring的web应用中,一般会在controller层获取http方法body中的数据. 方式1: 比如http请求的content-type为appli ...