Tju : 1541


//============================================================================
// Name        : Tju_1541.cpp
// Author      : Shahab
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstring>
using namespace std;

char input [100000];
long long dp [100000];

bool duet (int i)
{
    if ( input [i - 1] == '0' )
        return false;

	int num = (input [i - 1] - '0') * 10 + (input [i] - '0');

	if ( num >= 1 && num <= 26 )
		return true;
	return false;
}

int main()
{

	while ( scanf ("%s", input) && strcmp (input, "0") ) {
		dp [0] = 1;

		int length = strlen (input);
		long long x = 0;

		for ( int i = 1; i < length; i++ ) {
			if ( duet (i) ) {
				if ( i - 2 >= 0 )
					x = dp [i - 1] - dp [i - 2];

				if ( input [i] == '0' )
					dp [i] = dp [i - 1] - x;
				else
					dp [i] = dp [i - 1] * 2 - x;
			}
			else
				dp [i] = dp [i - 1];
		}

		printf ("%lld\n", dp [length - 1]);
	}

	return 0;
}
Advertisements

One thought on “Tju : 1541

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s