把当前数删除几位然后能够整除与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的更多相关文章

  1. cf306 C. Divisibility by Eight(数学推导)

    C. Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. 周赛-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 ...

  3. 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/ ...

  4. Divisibility by Eight (数学)

    Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. codeforces 630J Divisibility

    J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...

  6. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  7. Divisibility

    Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...

  8. HDU 3335 Divisibility (DLX)

    Divisibility Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  9. light oj 1078 - Integer Divisibility

    1078 - Integer Divisibility   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...

  10. POJ 1745 Divisibility (线性dp)

    Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10598   Accepted: 3787 Des ...

随机推荐

  1. CSS Flex布局属性整理

    Flex布局 display: flex; 将对象作为弹性伸缩盒展示,用于块级元素 display: inline-flex; 将对象作为弹性伸缩盒展示,用于行内元素 注意兼容问题: webkit内核 ...

  2. IoC Containers with Xamarin

    When writing cross platform apps with Xamarin, our goal is share as close to 100% of our code across ...

  3. 关于TFS2010 远程无法创建团队项目的若干问题总结

    今天遇到一个TFS的问题,折腾了好几个小时,故将其记录,给有遇到类似问题的朋友一些参考. 1.本文前提:服务器端只安装了TFS2010,本地没有安装Visual Studio 2010,因此不能在服务 ...

  4. xtraTabbedMdiManager 双击最大化和关闭后返回主界面 z

    双击tab头部时候子窗体Float时界面最大化和关闭Float状态的子窗体并不是真正关闭而是回到主界面的问题, 代码如下,其中xtraTabbedMdiManager1_Floating这个是xtra ...

  5. 利用localStorage实现对ueditor编辑内容定时保存为草稿

    直接看代码吧 1.引入ueditor和ueditor的使用我就不细说了 详情请戳http://blog.csdn.net/wangdianyong/article/details/39780709 2 ...

  6. ConcurrentHashMap之实现细节

    ConcurrentHashMap是Java 5中支持高并发.高吞吐量的线程安全HashMap实现.在这之前我对ConcurrentHashMap只有一些肤浅的理解,仅知道它采用了多个锁,大概也足够了 ...

  7. tomcat配置manager

    tomcat-users.xml配置 <role rolename="manager-gui"/><user username="tomcat" ...

  8. [PHP] ubuntu16.04配置Lamp环境(搭建linux+apache+mysql+php7环境)

    reference : http://blog.csdn.net/Abyss_sliver/article/details/77621404 好久没有在Linux环境下进行开发了,比较常用的还是win ...

  9. IDEA的注册

    步骤: license server -> 属性 -> 允许作为程序执行文件 即 chmod 777

  10. error: 'release' is unavailable: not available in automatic reference counting,该怎么解决

    编译出现错误: 'release' is unavailable: not available in automatic reference counting mode.. 解决办法: You nee ...