B. New Skateboard

题目连接:

http://www.codeforces.com/contest/628/problem/A

Description

Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.

You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.

A substring of a string is a nonempty sequence of consecutive characters.

For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.

Output

Print integer a — the number of substrings of the string s that are divisible by 4.

Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Sample Input

124

Sample Output

4

Hint

题意

给你一个只含有数字的串,然后问你有多少个子串是4的倍数,可以有前导0

题解:

4的倍数的话,当且仅当这个数的个位和十位能被4整除

那么我们扫一遍统计一下就好了,如果这个个位和十位能被4整除,那么他的贡献就是他是整个字符串的第几位

因为他和他的前缀组合起来肯定也是4的倍数

代码

#include<bits/stdc++.h>
using namespace std; string s;
int main()
{
cin>>s;
long long ans = 0;
for(int i=0;i<s.size();i++)
if((s[i]-'0')%4==0)
ans++;
for(int i=1;i<s.size();i++)
if(((s[i-1]-'0')*10+(s[i]-'0'))%4==0)
ans+=1ll*i;
cout<<ans<<endl;
}

Educational Codeforces Round 8 B. New Skateboard 暴力的更多相关文章

  1. Educational Codeforces Round 8 A. Tennis Tournament 暴力

    A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tour ...

  2. Educational Codeforces Round 1 A. Tricky Sum 暴力

    A. Tricky Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem ...

  3. Educational Codeforces Round 8 B. New Skateboard

    题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简 ...

  4. Educational Codeforces Round 19 E. Array Queries(暴力)(DP)

    传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...

  5. Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)

    You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...

  6. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. Educational Codeforces Round 59 (Rated for Div. 2) DE题解

    Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...

  9. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

随机推荐

  1. Windows 10又现新Bug,24核心竟卡成蜗牛

    Windows 10又现新Bug,24核心竟卡成蜗牛 https://news.cnblogs.com/n/573996/

  2. Sqlserver获取所有数据库名,表信息,字段信息,主键信息,以及表结构等。

    --获取所有数据库名: SELECT name FROM master..sysdatabases WHERE name NOT IN ( 'master', 'model', 'msdb', 'te ...

  3. Shell三剑客之sed命令

    Sed简介 Sed是Stream Editor(流编辑器)缩写,是操作.过滤和转换文本内容的强大工具,常用功能有增删改查. Sed命令执行流程 Sed语法格式 Sed [option] ‘[匹配][处 ...

  4. C语言inline函数(转)

    原文链接:http://blog.csdn.net/yuan1125/article/details/6225993 1  inline只是个编译器建议,编译器不一定非得展开Inline函数. 例如: ...

  5. Can't load standard profile: GRAY.pf

    报错: java.lang.IllegalArgumentException: Can't load standard profile: GRAY.pf at java.awt.color.ICC_P ...

  6. java虚拟机字节码执行引擎

    定义 java虚拟机字节码执行引擎是jvm最核心的组成部分之一,它做的事情很简单:输入的是字节码文件,处理过程是字节码解析的等效过程,输出的是执行结果.在不同的虚拟机实现里,执行引擎在执行java代码 ...

  7. ReentrantLock 学习

    Java接口Lock有三个实现类:ReentrantLock.ReentrantReadWriteLock.ReadLock和ReentrantReadWriteLock.WriteLock.Lock ...

  8. 安装node的最新版本

    前段时间小试了一下node 这段时间就差不多忘了 恩 然后现在自己想去回顾一下,然后流程想再好好弄一遍 争取掌握node 因为我现在已经安装了 一个node版本 那我想安装最新版本吧 首先,看看你的n ...

  9. .vue,跟小程序文件在sublime里面怎么实现代码格式化

    .vue文件跟小程序的.wxml,.wxss用sublime的HTML/CSS/JS prettify插件也可以实现格式化代码的效果 首先你在sublime要已经安装好了HTML/CSS/JS pre ...

  10. 《深入浅出MyBatis技术原理与实战》——4. 映射器,5. 动态SQL

    4.1 映射器的主要元素 4.2 select元素 4.2.2 简易数据类型的例子 例如,我们需要统计一个姓氏的用户数量.应该把姓氏作为参数传递,而将结果设置为整型返回给调用者,如: 4.2.3 自动 ...