博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 字符串+数论
阅读量:4112 次
发布时间:2019-05-25

本文共 2435 字,大约阅读时间需要 8 分钟。

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

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.

Output

Print "NO" (without quotes), if there is no such way to remove some digits from number n.

Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Sample test(s)
input
3454
output
YES344
input
10
output
YES0
input
111111
output
NO
题意:给你一个不超过100位的数,判断能否通过删除其中一些(可以不删)数位,使得剩下的数字能
被8整除;
自己写的代码;
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define MM(a) memset(a,0,sizeof(a)) typedef long long ll; typedef unsigned long long ULL; const int mod = 1000000007; const double eps = 1e-10; const int inf = 0x3f3f3f3f; const int big=50000; int max(int a,int b) { return a>b?a:b;}; int min(int a,int b) { return a
下面是看了网上的代码;
1.sprintf的使用,非常方便,转换成了字符串;
2.字符与字符之间相与,只要两个均非空即是真;
#include 
#include
#include
#include
#include
#include
char a[100005]; int main() { while(~scanf("%s",a)) { bool flag=false; for(int i=0;i<1000;i++) if(i%8==0) { char b[5]; sprintf(b,"%d",i); int p=0; for(int i=0;a[i]&&b[p];i++) { if(a[i]==b[p]) p++; } if(!b[p]) { printf("YES\n%s\n",b); flag=true; } if(flag) break; } if(!flag) printf("NO\n"); } return 0; }
分析:一个数字能否被8整除,只要判断其最后三位能否被8整除就好(因为1000可被8整除)

转载地址:http://uxgsi.baihongyu.com/

你可能感兴趣的文章
UE4课堂笔记——《UE4C++游戏开发入门教程!》第三期创建组件(静态网格体实现摄像头追踪)
查看>>
PHP开发日志 ━━ PHP格式化显示时间date()函数代码
查看>>
PLUPLOAD插件 ━━ 上传总结(分片上传,php后端处理)
查看>>
微信开发 ━━ 微信支付之商户API证书获得
查看>>
微信开发 ━━ 微信商户v3微信支付Navive方式开发之php篇
查看>>
微信开发 ━━ 微信商户v3微信支付H5方式开发之php篇
查看>>
Windows下创建OpenSSL自签证书及将Windows已有证书pfx文件转化成key、crt文件
查看>>
uni-app开发日志[2021061201]:将uni.request异步模式改装成同步模式,uni-app基于Promise的request请求封装
查看>>
PHP开发日志 ━━ php、javascript生成二维码的三种方法
查看>>
五行相生相克基础篇
查看>>
k8s学习笔记-环境准备
查看>>
k8s学习笔记-创建CA 证书和密钥
查看>>
k8s学习笔记-部署ETCD3.4集群
查看>>
k8s学习笔记-部署Flannel网络
查看>>
k8s学习笔记-部署master节点
查看>>
k8s学习笔记-部署kubectl命令工具
查看>>
k8s学习笔记-部署node节点
查看>>
【转载】究竟什么是图数据库,它有哪些应用场景?
查看>>
【转载】P2P镜像分发Dragonfly使用
查看>>
【转载】网络安全体系设计方法论
查看>>