Divisibility by Eight
把当前数删除几位然后能够整除与8
那么可得知大于3位数的推断能否整除于八的条件是(n%1000)%8==0
能够得出我们的结论:仅仅须要枚举后三位后两位后一位就可以知道是否可整除于8
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char a[200];
int main() {
//printf("%d\n",344%8);
int ans = 0 ;
int flag = 0;
scanf("%s",a);
int l = strlen(a);
if(l>=3) {
for(int i=0; i<l-2; ++i) {
if(a[i]=='0') continue;
for(int j=i+1; j<l-1; ++j) {
for(int k=j+1; k<l; ++k) {
ans = (a[i]-'0')*100+(a[j]-'0')*10+a[k]-'0';
if(ans%8==0){
flag=1;
break;
}
}
if(flag) break;
}
if(flag)break;
}
}
// printf(" %d %d\n",flag,ans);
if(!flag&&l>=2) {
for(int i=0; i<l-1; ++i) {
if(a[i]=='0') continue;
for(int j=i+1; j<l; ++j) {
ans = (a[i]-'0')*10+(a[j]-'0');
if(ans%8==0) {
flag=1;
break;
}
}
if(flag) break;
}
}
if(!flag) {
for(int i=0; i<l; ++i)
if((a[i]-'0')%8==0) {
ans=a[i]-'0';
flag=1;
break;
}
}
if(!flag) {
puts("NO");
} else puts("YES"),printf("%d\n",ans);
}
Divisibility by Eight的更多相关文章
- cf306 C. Divisibility by Eight(数学推导)
C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏
Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...
- Codeforces Round #306 (Div. 2) C. Divisibility by Eight 暴力
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Divisibility by Eight (数学)
Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces 630J Divisibility
J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Divisibility
Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...
- HDU 3335 Divisibility (DLX)
Divisibility Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- light oj 1078 - Integer Divisibility
1078 - Integer Divisibility PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- POJ 1745 Divisibility (线性dp)
Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10598 Accepted: 3787 Des ...
随机推荐
- linux系统编程:线程原语
线程原语 线程概念 线程(thread),有时被称为轻量级进程(Lightweight Process,LWP).是程序运行流的最小单元.一个标准的线程由线程ID.当前指令指针(PC),寄存器集合和堆 ...
- Visual Studio调试的10个技巧
本篇体验Visual Studio的10个调试技巧,包括: 1.插入断点和断点管理2.查看变量信息3.逐语句F11,逐过程F10,跳出Shift+F114.查看堆栈信息5.设置下一条执行语句6.调试时 ...
- MySQL数据库事务各隔离级别加锁情况--read uncommitted篇(转)
本文转自https://m.imooc.com/article/details?article_id=17291,感谢作者 1.目的 1.1 合适人群 1.数据库事务特征我只是背过,并没有很深刻的理解 ...
- nginx简单代理配置
原文:https://my.oschina.net/wangnian/blog/791294 前言 Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器, ...
- Android项目实战之(1)-- 开发一个"快速冲浪"的程序
概述:这个小程序,你讲学习到基本控件(Button,Listview,Gridview,TextView等)的使用技巧,AssetManager类的使用,XML数据的解析方式,BaseAdapter, ...
- 【spring cloud】【IDEA】【Maven】spring cloud多模块打包,打包的jar包只有几k,jar包无法运行,运行报错:no main manifest attribute, in /ms-eureka.jar
======================================================================================== 引申:maven打包多 ...
- iOS 下 Podfile 使用方法
配置 Podlist Pod 是 iOS 下包管理工具,类似于 JavaScript 里的 npm 或 yarn. 创建 Podfile 创建 Podfile 有两种方式: 打开 Terminal,在 ...
- 关于Unity中Shader的内置值
Unity provides a handful of builtin values for your shaders: things like current object's transforma ...
- html 中怎么设置div的位置
利用CSS的position属性对元素定位,以下是position 属性规定元素的定位类型. absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位.元素的位置通过 ...
- 第二章 ActionScript 3.0学习之画星星(鼠标及键盘事件)
今天觉得学到的比较有趣,所以记录之......~~~ 下面这段就是画出星星的代码:StarShape.as package { import flash.display.Shape; import f ...