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 ...
随机推荐
- Android项目文件夹结构分析
项目结构例如以下图所看到的,使用不同sdk版本号建立的项目项目结构有所不同,整体同样,高版本号添加了一些包结构 1.src 和java项目一样src存放项目源码 2.gen 自己主动生成,当中R.ja ...
- Monotouch/WCF: How to consume the wcf service without svcutil
Becuase monotouch compile to native code, so it has some limitation such as dynamic invoke is not al ...
- HTML5 vs FLASH vs SILVERLIGHT
Introduction HTML5 kills off flash; HTML5 kills off Silverlight; HTML5 makes the dinner and does the ...
- log4j用properties文件配置,无法应用过滤器的解决方法
properties文件仍然有错误 log4j:WARN Failed to set property [filter] to value "org.apache.log4j.varia.L ...
- arcgis python 创建 SQLite 数据库
# -*- ################# """ Tool name: Create SQLite Database Source: CreateSQLiteDat ...
- 日期时间篇asctime ctime gettimeofday gmtime localtime mktime settimeofday time
asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime,localtime 表头文件 #include<time.h> 定义函数 char * asc ...
- 四边形优化dp
理解: http://blog.renren.com/share/263498909/1064362501 http://www.cnblogs.com/ronaflx/archive/2011/03 ...
- C语言中static的作用及C语言中使用静态函数有何好处
转自:http://www.jb51.net/article/74830.htm 在C语言中,static的作用有三条:一是隐藏功能,二是保持持久性功能,三是默认初始化为0. 在C语言中,static ...
- C/C++中printf/cout 计算顺序与缓冲区问题
1.printf/cout在同一个语句中都是从右向左计算的. 看如下的代码: #include <stdio.h> int main() { ; printf("%d %d&qu ...
- crtmpserver实现防盗流和流推送验证 之二
IV. Catching the thieves 抓住小偷 Well, we have just added a secure mechanism to our little streaming se ...