A. Even Substrings
A. Even Substrings
0.5 seconds
256 megabytes
standard input
standard output
You are given a string s=s1s2…sns=s1s2…sn of length nn, which only contains digits 11, 22, ..., 99.
A substring s[l…r]s[l…r] of ss is a string slsl+1sl+2…srslsl+1sl+2…sr. A substring s[l…r]s[l…r] of ss is called even if the number represented by it is even.
Find the number of even substrings of ss. Note, that even if some substrings are equal as strings, but have different ll and rr, they are counted as different substrings.
Input
The first line contains an integer nn (1≤n≤650001≤n≤65000) — the length of the string ss.
The second line contains a string ss of length nn. The string ss consists only of digits 11, 22, ..., 99.
Output
Print the number of even substrings of ss.
Examples
input
- 4
- 1234
output
- 6
input
- 4
- 2244
output
- 10
Note
In the first example, the [l,r][l,r] pairs corresponding to even substrings are:
- s[1…2]s[1…2]
- s[2…2]s[2…2]
- s[1…4]s[1…4]
- s[2…4]s[2…4]
- s[3…4]s[3…4]
- s[4…4]s[4…4]
In the second example, all 1010 substrings of ss are even substrings. Note, that while substrings s[1…1]s[1…1] and s[2…2]s[2…2] both define the substring "2", they are still counted as different substrings.
题意:任取主串中的一个区间,判断这个是减是不是偶数,然后是偶数的话,就数量加1,找出有多少个这样的偶数区间。比如:第一个样例1234,其中12,2,1234,234,34,4为偶数,所以答案是6。其思路是从第一个字符遍历到最后一个字符,如果遇到偶数,就将这个数的位数加入sum中,依次遍历过就行。
- #include<iostream>
- #include<cstdio>
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- string s;
- cin>>s;
- int sum=;
- for(int i=;i<n;i++)
- if((s[i]-'')%==) //判断当前数字是不是偶数
- sum+=i+; //加上当前数字的位数
- cout<<sum<<endl;
- return ;
- }
A. Even Substrings的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- LA4671 K-neighbor substrings(FFT + 字符串Hash)
题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...
- 后缀数组---New Distinct Substrings
Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...
- Codeforces Round #258 D Count Good Substrings --计数
题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...
- SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转
694. Distinct Substrings Problem code: DISUBSTR Given a string, we need to find the total number o ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- CF Two Substrings
Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- Ruby学习中(哈希变量/python的字典, 简单的类型转换)
一. 哈希变量(相当于Python中的字典) 详情参看:https://www.runoob.com/ruby/ruby-hash.html 1.值得注意的 (1). 创建Hash时需注意 # 创建一 ...
- 如何用纯 CSS 创作六边形按钮特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xjoOeM 可交互视频教 ...
- 如何用纯 CSS 创作一个菜单反色填充特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览.https://codepen.io/comehope/pen/qYMoPo 可交互视频教程 ...
- python 目录管理与文件管理
目录管理(os) system:执行系统命令 # 执行系统命令 os.system('cls') name:获取操作系统名称 # 操作系统名称,nt代表Windows, posix代表类unix pr ...
- postgres导入和导出
导出整个数据库: pg_dump -h 127.0.0.1 -U zhang mydb >mydb_dum.sql 导出某个表: pg_dump -h 127.0.0.1 -U zhang my ...
- shell脚本中的一些特殊符号
在shell中常用的特殊符号罗列如下: # ; ;; . , / \\ 'string'| ! $ ${} $? $$ $* \"string\"* ** ...
- linux yum 安装及卸载
在Centos中yum安装和卸载软件的使用方法安装方法安装一个软件时yum -y install httpd安装多个相类似的软件时yum -y install httpd*安装多个非类似软件时yum ...
- SEO黑页以及门页框架和JS跳转实现方法
在去年大家还在针对第三方博客狂轰乱炸,比如:webs.com.blogspot.com.weebly.com主要是因为本身博客平台的权重,再就是低廉的成本,主需要注册,没有域名和服务器的投入.排名也非 ...
- web性能优化-浏览器工作原理
要彻底了解web性能优化的问题,得搞清楚浏览器的工作原理. 我们需要了解,你在浏览器地址栏中输入url到页面展示的短短几秒中,浏览器究竟做了什么,才能了解到为什么我们口中所说的优化方案能够起到优化作用 ...
- 深入理解java不可变对象(转)
深入理解Java中的不可变对象 不可变对象想必大部分朋友都不陌生,大家在平时写代码的过程中100%会使用到不可变对象,比如最常见的String对象.包装器对象等,那么到底为何Java语言要这么设计,真 ...