Sicily 1001

1001. Alphacode

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Alice and Bob need to send secret messages to each other and are discussing ways to encode theirmessages: Alice: "Let‘s just use a very simple code: We‘ll assign `A‘ the code word 1, `B‘ will be 2, and so on down to `Z‘ being assigned 26." Bob: "That‘s a
stupid code, Alice. Suppose I send you the word `BEAN‘ encoded as 25114. You could decode that in many different ways!" Alice: "Sure you could, but what words would you get? Other than `BEAN‘, you‘d get `BEAAD‘, `YAAD‘, `YAN‘, `YKD‘ and `BEKD‘. I think you
would be able to figure out the correct decoding. And why would you send me the word `BEAN‘ anyway?" Bob: "OK, maybe that‘s a bad example, but I bet you that if you got a string of length 500 there would be tons of different decodings and with that many you
would find at least two different ones that would make sense." Alice: "How many different decodings?" Bob: "Jillions!"For some reason, Alice is still unconvinced by Bob‘s argument, so she requires a program that willdetermine how many decodings there can be
for a given string using her code.

Input

Input will consist of multiple input sets. Each set will consist of a single line of digits representing avalid encryption (for example, no line will begin with a 0). There will be no spaces between the digits.An input line of `0‘ will terminate the input
and should not be processed

Output

For each input set, output the number of possible decodings for the input string. All answers will bewithin the range of a long variable.

Sample Input

25114
1111111111
3333333333
0

Sample Output

6
89
1
#include<iostream>
#include<cstring>
using namespace std;
bool  is_letter(char begin,char end)
{
	if(begin>='3') return false;
	else if(begin=='2')
	{
	//	cout<<"end"<<end<<endl;
		if(end<='6');
		return true;

		return false;
	}
	else if(begin=='0') return false;
	else return true;
}
int main()
{
	char num[10000];
	long long n_way[10000];

	while(cin>>num)
	{
		if(num[0]=='0') break;
		memset(n_way,0,sizeof(n_way));
		n_way[0]=1;

		if(is_letter(num[0],num[1])==1&&num[1]!='0') n_way[1]=2;

		else
		{
			n_way[1]=1;
		}
		for(int i=2;i<strlen(num);i++)
		{
			if(num[i]=='0') n_way[i]=n_way[i-2];
			else if(is_letter(num[i-1],num[i])==0) n_way[i]=n_way[i-1];
			else n_way[i]=n_way[i-1]+n_way[i-2];
		}
	/*	for(int i=0;i<strlen(num);i++)
		{
			cout<<n_way[i]<<endl;
		}*/
		cout<<n_way[strlen(num)-1]<<endl;

	}
	return 0;
}
时间: 2024-10-07 12:47:44

Sicily 1001的相关文章

sicily 1001. Fibonacci 2

1001. Fibonacci 2 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + Fn-2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … Given an integer n, your goal is to co

Sicily 1001. Alphacode

1001. Alphacode Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Alice and Bob need to send secret messages to each other and are discussing ways to encode their messages: Alice: "Let's just use a very simple code: We'll assign `A' the

Sicily 1001(dp)

题目连接:http://soj.sysu.edu.cn/1001 解题报告:f[i]表示第i个字母前能组成的种类 情况:1.s[i]==0,f[i]=f[i-1] 2.s[i-1]*10+s[i]>=10&&<=26,f[i]=f[i-1]+f[i-2] 3.!s[i-1]*10+s[i]>=10&&<=26,f[i]=f[i-1]; #include <iostream> #include <cstring> #includ

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

paste 乙级 1001

1001. 害死人不偿命的(3n+1)猜想 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业

1001 数组中和等于K的数对

1001 数组中和等于K的数对 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数,找出数组A中所有和等于K的数对.例如K = 8,数组A:{-1,6,5,3,4,2,9,0,8},所有和等于8的数对包括(-1,9),(0,8),(2,6),(3,5). Input 第1行:用空格隔开的2个数,K N,N为A数组的长度.(2 <= N <= 50000,-10^9 <= K <= 10^9)

杭电女生赛1001 1002 1003 1005 1008 hdu6023 6024 6025 6027 6030

代码先贴这里 #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm&quo

BZOJ 1001 [BeiJing2006]狼抓兔子

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 题意: ... 很容易想到求的是一个最小割=最大流. 之前一直用的刘汝佳的模板STL过题,很久没用过数组模拟了. 再次熟悉一下写法,first数组是索引数组,标记的结点的最后一条边,利用next数组找到上一条边. 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define N 1100000 6 int n,m,

求最大边/最小边的比值最小的路径 codevs 1001 舒适的路线

codevs 1001 舒适的路线 2006年 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤5000)条道路连接着,所有道路都是双向的,两个景点之间可能有多条道路.也许是为了保护该地的旅游资源,Z小镇有个奇怪的规定,就是对于一条给定的公路Ri,任何在该公路上行驶的车