fork download
  1. #include<algorithm>
  2. #include<bits/stdc++.h>
  3. #include<map>
  4. #include<queue>
  5. #include<stack>
  6. #include<set>
  7. #include<vector>
  8. #define ll long long
  9. using namespace std;
  10. #define i(x) (x+'0')
  11. bool div8(string s)
  12. {
  13. int n=s.length(),ans=0;
  14. if(n>=3)
  15. for(int i=n-3,j=2;i<n;i++,j--)
  16. ans+=(s[i]-'0')*pow(10,j);//,cout<<"ans: "<<ans<<endl;
  17. else
  18. for(int i=n-2,j=1;i<n;i++,j--)
  19. ans+=(s[i]-'0')*pow(10,j);//,cout<<"ans: "<<ans<<endl;
  20. if(ans%8==0)
  21. return true;
  22. else return false;
  23. }
  24. int main()
  25. {
  26. //freopen("ip.txt","r",stdin);
  27. int fl,fl1,ans,pos;
  28. string s;
  29. string ch[]={"0","8","16","24","32","40","48","56","64","72","80","88","96","104","112","120","128","136","144","152","160","168","176","184","192","200","208","216","224","232","240","248","256","264","272","280","288","296","304","312","320","328","336","344","352","360","368","376","384","392","400","408","416","424","432","440","448","456","464","472","480","488","496","504","512","520","528","536","544","552","560","568","576","584","592","600","608","616","624","632","640","648","656","664","672","680","688","696","704","712","720","728","736","744","752","760","768","776","784","792","800","808","816","824","832","840","848","856","864","872","880","888","896","904","912","920","928","936","944","952","960","968","976","984","992"};
  30. int size=sizeof(ch)/sizeof(string);
  31. cin>>s;
  32. int n=s.length();
  33. if(n==1)
  34. {
  35. if(s=="8" || s=="0")
  36. cout<<"YES\n"<<s<<endl;
  37. else cout<<"NO\n";
  38. }
  39. else
  40. {
  41. if(div8(s))
  42. {
  43. cout<<"YES\n"<<s<<endl;
  44. return 0;
  45. }
  46. fl=0;
  47. pos=0;
  48. for(int i=0;i<size;i++)
  49. {
  50. if(ch[i].length()>n)
  51. {
  52. fl=-1;
  53. break;
  54. }
  55. else
  56. {
  57. int k=0;
  58. fl1=0;
  59. for(int j=0;j<ch[i].length();j++)
  60. {
  61. while(k<n)
  62. {
  63. if (s[k]==ch[i][j])
  64. {
  65. fl1++;
  66. k++;
  67. break;
  68. }
  69. k++;
  70. }
  71. if(k>=n && fl1<ch[i].length())
  72. break;
  73. }
  74. if(fl1==ch[i].length())
  75. {
  76. pos=i;
  77. fl=1;
  78. break;
  79. }
  80. }
  81. }
  82. if(fl==0 || fl==-1)
  83. cout<<"NO\n";
  84. else if(fl==1)
  85. {
  86. cout<<"YES\n";
  87. //cout<<"pos"<<pos<<endl;
  88. cout<<ch[pos]<<endl;
  89. }
  90. }
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 3240KB
stdin
 3111111111111111111111411111111111111111111141111111441 
stdout
YES
144