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的更多相关文章
随机推荐
- ural1553 Caves and Tunnels
Caves and Tunnels Time limit: 3.0 secondMemory limit: 64 MB After landing on Mars surface, scientist ...
- Protocol buffers--python 实践(一) 简介以及安装与使用
由于最近对grpc产生了浓厚的兴趣,但是那是一整套东西,看了一下用到的东西不少,所以抽丝剥茧先写写这几天调研的protocol buffer -python的收获. 简介: 以下引用自官方首页文档: ...
- 数据恢复软件Extundelete
数据恢复软件Extundelete介绍 一.概述 作为一名运维人员,保证数据的安全是根本职责,所以在维护系统的时候,要慎重和细心,但是有时也难免发生出现数据被误删除的情况,这个时候该如何快速.有效地恢 ...
- sublime text3 Emmet (原zenCoding)安装方法
1.安装使用Package Control组件安装 (1)打开控制台 (mac)control+`; (win)ctrl+` (2)复制一下代码并回车 import urllib.request,os ...
- iReport使用教程
http://www.blogjava.net/keweibo/articles/239492.html 原创出处 http://blog.163.com/liushuo216@126/blog/st ...
- Android之事件分发
网上总结的很详细了,有时间总结下做个笔记
- matlab中gatbx工具箱的添加
1. 从http://crystalgate.shef.ac.uk/code/下载工具箱压缩包gatbx.zip 2. 解压gatbx.zip,将其子文件夹genetic放在matlab安装目录too ...
- ServerSocketChannel
Java NIO 中的 ServerSocketChannel 是一个可以监听新进来的 TCP 连接的通道, 就像标准 IO 中的 ServerSocket 一样.ServerSocketChanne ...
- P4语言编程快速开始 实践二
参考:P4语言编程快速开始 上一篇系列博客:P4语言编程快速开始 实践二 Demo 2 本Demo所做的修改及实现的功能: 为simple_router添加一个计数器(counter),该计数器附加( ...
- 使用idea建立gradle+SSM项目
目录: 一.创建一个gradle项目 二 .在gradle中创建SSM项目 一 .创建一个gradle项目 第一步: 第二步:选择gradle,并选中web,然后点击Next进入下一步 第三步:此 ...