-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiv_by_8.cpp
More file actions
executable file
·73 lines (71 loc) · 2.48 KB
/
div_by_8.cpp
File metadata and controls
executable file
·73 lines (71 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mk_arr(n, t, s) t* n = new t[s]; loop(s) cin >> n[i];
#define mi_arr(n, s) int* n = new int[s]; loop(s) cin >> n[i];
#define arr_out(n, s) Loop(0, s, lout) cout << n[lout] << " ";
#define pi(x) printf("%lld ", x);
#define mod 1000000007
int32_t main(){
string str;
cin >> str;
int len = str.length();
int ans = 0;
bool flag = false;
if(len == 1){
if(str[0] == '0' || str[0] == '8') ans = str[0]-'0', flag = true;
}
else if(len == 2){
int temp = (str[1]-'0')*10 + (str[0]-'0');
if(temp%8 == 0) ans = temp, flag = true;
else if(str[1] == '8' || str[1] == '0') ans = str[1]-'0', flag = true;
else if(str[0] == '8') ans = 8, flag = true;
}
else{
map<int, int> mp;
for(int i = 100; i < 1000; i++) if(i%8 == 0){
mp[i/10] = i%10;
}
bool arr[len][10];
memset(arr, 0, sizeof(arr));
for(int i = len-2; i >= 0; i--){
for(int j = 0; j < 10; j++){
arr[i][j] = arr[i+1][j];
}
arr[i][str[i+1]-'0'] = true;
}
// for(int i = 0; i < len; i++){
// cout << str[i] << " ";
// for(int j = 0; j < 10; j++) cout << arr[i][j] << " ";
// cout << endl;
// }
for(int i = 0; i < len; i++){
if((str[i]-'0')%8 == 0){ ans = str[i]-'0', flag = true; break;}
for(int j = i+1; j < len; j++){
int temp = (str[i]-'0')*10 + str[j]-'0';
if(temp%8 == 0){
ans = temp;
flag = true;
break;
}
else{
if(arr[j][mp[temp]]) {ans = temp*10 + mp[temp], flag = true; break;}
}
}
}
}
if(flag) cout << "YES\n" << ans << endl;
else cout << "NO" << endl;
}