版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mystery_guest/article/details/69053952
然而自己根本就不会啊。数学真菜啊
求这些数字任意删除,最终结果如果能整除8则输出最后的数,否则NO
自己当时敲了个pow(2,str.size())的暴力,当时看错以为范围是10,然而题目是100,直接WA
其实对于8来说,只要找到1位数,2位数,或者3位数能整除8即可。四位数及以上可以不用找了,为什么呢?因为1000是最小的四位数,它是能整除8的,所以n*1000+m(m表示一个三位数或者二位数或者一位数),(n*1000+m)%8,即m%8。到这里就很水了。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define eps 1e-8
#define zero(x) (((x>0?(x):-(x))-eps)
#define mem(a,b) memset(a,b,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define ull unsigned long long
#define sf(a) scanf("%d",&a)
#define sf64(a) scanf("%I64d",&a)
#define sf264(a,b) scanf("%I64d%I64d",&a,&b)
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sf464(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define sf564(a,b,c,d,ee) scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&ee)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sf5(a,b,c,d,ee) scanf("%d%d%d%d%d",&a,&b,&c,&d,&ee)
#define sff(a) scanf("%f",&a)
#define sfs(a) scanf("%s",a)
#define sfs2(a,b) scanf("%s%s",a,b)
#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)
#define sfd(a) scanf("%lf",&a)
#define sfd2(a,b) scanf("%lf%lf",&a,&b)
#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)
#define sfc(a) scanf("%c",&a)
#define ull unsigned long long
#define pp pair<int,int>
#define debug printf("***\n")
#define pi 3.1415927
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a, int b){ return a>b; }
bool cmpsmall(int a, int b){ return a<b; }
using namespace std;
int main()
{
// freopen("data.in","r",stdin);
//freopen("data.out" ,"w",stdout);
string str;
while(cin>>str)
{
rep(i,0,str.size())
{
int num=str[i]-'0';
if(num%8==0)
{
cout<<"YES"<<endl<<str[i]<<endl;
return 0;
}
}
rep(i,0,str.size())
rep(j,i+1,str.size())
{
int num=(str[i]-'0')*10+(str[j]-'0');
if(num%8==0)
{
cout<<"YES"<<endl<<str[i]<<str[j]<<endl;
return 0;
}
}
rep(i,0,str.size())
rep(j,i+1,str.size())
rep(k,j+1,str.size())
{
int num=(str[i]-'0')*100+(str[j]-'0')*10+(str[k]-'0');
if(num%8==0)
{
cout<<"YES"<<endl<<str[i]<<str[j]<<str[k]<<endl;
return 0;
}
}
cout<<"NO"<<endl;
}
return 0;
}