CodeForces 628B New Skateboard-数学水题
2016-03-12 22:17
471 查看
给一个字符串
让你求他的substring 中有多少个能整除4
题目特意强调了 A substring can start with
a zero.
4结果我智障地读成 子串只能有一个前导零
妈的智障
一开始就把前导零去掉了。。。。。把这段注释掉就ac了。。
就是一个数的末尾两位数如果能被4整除 则 这个数能被4整除,
直接for一遍,就OK了
智障!
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
#include <cfloat>
const double pi=acos(-1.0);
double eps=0.000001;
char tm[300005];
int main()
{
scanf("%s",tm+1);
int n=strlen(tm+1);
int i,j;
__int64 sum=0;
int st=1;
for (i=n;i>=st;i--)
{
__int64 x=tm[i]-'0';
if (x%4==0)
sum+=1;
if (i==st)continue;
x+=(tm[i-1]-'0')*10;
if (x%4==0)
sum+=i-st;
}
printf("%I64d\n",sum);
return 0;
}
让你求他的substring 中有多少个能整除4
题目特意强调了 A substring can start with
a zero.
4结果我智障地读成 子串只能有一个前导零
妈的智障
一开始就把前导零去掉了。。。。。把这段注释掉就ac了。。
就是一个数的末尾两位数如果能被4整除 则 这个数能被4整除,
直接for一遍,就OK了
智障!
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
#include <cfloat>
const double pi=acos(-1.0);
double eps=0.000001;
char tm[300005];
int main()
{
scanf("%s",tm+1);
int n=strlen(tm+1);
int i,j;
__int64 sum=0;
int st=1;
for (i=n;i>=st;i--)
{
__int64 x=tm[i]-'0';
if (x%4==0)
sum+=1;
if (i==st)continue;
x+=(tm[i-1]-'0')*10;
if (x%4==0)
sum+=i-st;
}
printf("%I64d\n",sum);
return 0;
}
相关文章推荐
- Android MVP 介绍
- 21. Merge Two Sorted Lists
- 88. Merge Sorted Array
- 第33讲项目2——求阶乘
- Spark容错机制
- 用户与用户组权限管理详解
- QQ群中一次问答面试题,供大家借鉴,哈哈
- java反射
- c++第二次上机作业
- 集体智慧编程(二)发现群组
- JSP的四种属性范围
- C++ explicit关键字详解
- dhu4508(完全背包)
- BestCoder Round #75
- C/C++中字符串问题汇总
- Android-使用绝对布局管理器固定组件的位置
- Ubuntu搭建Ruby on Rails环境
- 六款值得推荐的android(安卓)开源框架简介
- sort -k选项详解
- MySQL学习笔记之四:并发控制和事务机制