CodeForces-1139A-Even Substrings

本文介绍了一道关于字符串处理的编程题目,任务是找出给定数字字符串中所有偶数子串的数量。文章提供了完整的代码实现,采用C++语言,通过遍历字符串并判断每个字符对应的数字是否为偶数来累加答案。

题目:

Description:

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.

题意分析:

阅读理解题,水题

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int ans=0,n;
char s[65005];
int main()
{
	scanf("%d",&n);
	scanf("%s",&s);
	for(int i=0;i<strlen(s);i++)
	{
		if((s[i]-'0')%2==0)ans+=(i+1);
	}
	printf("%d",ans);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值