Educational Codeforces Round 8 B. New Skateboard
题目链接:http://codeforces.com/problemset/problem/628/B
解题思路:
一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简单了
实现代码:
#include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <bitset> using namespace std; #define ll long long int main() { ll ans = 0,i,j,num,k; string s; cin>>s; int len = s.size(); for(i=0;i<len;i++){ num = s[i]-'0'; if(num%4==0) ans++; } //cout<<ans<<endl; if(len>=2){ for(i=0;i<len-1;i++){ num = (s[i] - '0')*10+(s[i+1]-'0'); if(num%4==0) ans++; } } //cout<<ans<<endl; if(len>=3){ for(i=0;i<len-1;i++){ num = (s[i] - '0')*10+(s[i+1]-'0'); if(num%4==0){ ans+=i; } //cout<<ans<<endl; } } cout<<ans<<endl; }