B. Inna and Nine

B. Inna and Nine
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.

Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.

For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and19991 which contain more digits nine.

Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.

Input

The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.

Output

In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Sample test(s)
input
369727
output
2
input
123456789987654321
output
1
input
1
output
1
Note

Notes to the samples

In the first sample Inna can get the following numbers: 369727 → 99727 → 9997369727 → 99727 → 9979.

In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.


     个人表示第一次看到这个题目以为是一个DP的问题,后来想想但是又不像,表示确实做的时候是没有思路,参考了   网上大神们的思路,惭愧,就要去比赛了,还这么水,是坑队友的节奏么。

  这个题目的做法是这样的,其实不同的情况只是在奇数的情况下,为啥这么说呢,454545,只能是999,但是45455

  就有三种,所以只有奇数才会有不同的,而规律就是个数/2+1,所以情况是每个奇数个数相乘就是了,用一个新的   数组来记住连续式的个数,只要是奇数,就让它满足/2+1如果发生了断电,就不加了。


  

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=100010;
int num[N];
int main(){
	char s[N];
	scanf("%s",s);
	memset(num,0,sizeof(num));
	__int64 sum=1;
	//cout<<"a "<<ch.size()<<endl;
	//cout<<"b "<<ch[ch.size()]<<endl;
	//cout<<"c "<<ch[ch.size()]-'0'<<endl;
	int l=strlen(s);
	for(int i=1;i<=l;i++)
	if(s[i]-'0'+s[i-1]-'0'==9)
	{
	    num[i]=num[i-1]+1;
	}
    else 
    if(num[i-1]>0&&num[i-1]%2==0) sum*=(num[i-1]/2+1);
	cout<<sum<<endl;

}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值