Codeforces374B
B. Inna and Nine
1 second
256 megabytes
standard input
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 cin, cout streams or the %I64dspecifier.
Examples
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 → 9997, 369727 → 99727 → 9979.
In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
//2016.11.19
#include <iostream>
#include <cstdio> using namespace std;
const int N = 1e5+;
int num[N], sum[N]; int main()
{
string str;
while(cin >> str)
{
long long ans = ;
int n = str.length();
for(int i = ; i < n; i++)
{
num[i] = str[i]-'';
if(i==)sum[i] = ;
else sum[i] = num[i] + num[i-];
}
for(int i = ; i < n; i++)
{
int cnt = ;
while(sum[i] == )
{
cnt++;
i++;
}
if(cnt && cnt%==)ans*=(cnt/+);
}
cout<<ans<<endl;
}
return ;
}
Codeforces374B的更多相关文章
随机推荐
- codeforce 611C New Year and Domino
n*n预处理. 询问的时候用容斥,再删除边界. #include<cstdio> #include<cstring> #include<cmath> #includ ...
- PAT 天梯赛 L2-1 紧急救援
Dijkstra算法扩展 题目链接 解题代码如下: #include<cstdio> #include<iostream> #include<algorithm> ...
- 我的云服务之WWW
云服务器系统是:[root@ip-172-31-27-132 system]# cat /etc/redhat-release Red Hat Enterprise Linux Server rele ...
- 根据XPATH去查看修改xml文件节点的内容
首先给出xml文件解析的路径,然后去读取节点的内容. package com.inetpsa.eqc.threads; import java.util.List; import java.io.Fi ...
- 前端设计——js实现图片切换的淡入淡出
1.网页结构如图所示 2.页面布局设计细节 ①分块:一个小方块是一个div. ②无序列表一般是竖直排放的,可以通过float让其水平排放.float:left; ③三个小方块是浮动上去的,所以要用到p ...
- 解决phpcms V9缩略图模糊的方法
解决V9缩略图模糊/libs/classes/image.class.php注释掉else imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x, ...
- 四、Hbase
一.什么情况下使用Hbase 例子: 这里Order By无时不刻的处理,我们要看到刚才的足迹,不能使用缓存技巧. 根据时间戳来查询,显然很快,应为Hbase就是以时间戳来存的. 将最近的数据放在内存 ...
- Android 状态栏通知Notification、NotificationManager详解
http://www.cnblogs.com/onlyinweb/archive/2012/09/03/2668381.html
- tp框架 使用ajax
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- iOS 之 内嵌网页
现在iOS 有两种内嵌网页的技术,一种是UIWebView,而另一种WKWebView则是iOS8之后出现的技术. iOS 之 UIWebView WKWebView