-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivi_8_n2.cpp
More file actions
43 lines (39 loc) · 946 Bytes
/
divi_8_n2.cpp
File metadata and controls
43 lines (39 loc) · 946 Bytes
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
#include <bits/stdc++.h>
#define d(x) (s[x] - '0')
using namespace std;
int dp[105][10] = {0};
string store[105][10];
char s[105];
int main()
{
scanf("%s", s);
dp[0][d(0) % 8]++;
store[0][d(0) % 8] = s[0];
for (int i = 1, l = strlen(s); i < l; i++)
for (int j = 0; j < 8; j++)
{
dp[i][d(i) % 8] = 1;
store[i][d(i) % 8] = s[i];
if (dp[i - 1][j])
{
store[i][j] = store[i - 1][j];
store[i][(j * 10 + d(i)) % 8] = store[i - 1][j] + s[i];
}
dp[i][(j * 10 + d(i)) % 8] |= dp[i - 1][j];
dp[i][j] |= dp[i - 1][j];
}
cout<<"displaying the dp matrix: "<<endl;
for(int i=0;i<strlen(s);i++)
{
cout<<endl;
for(int j=0;j<8;j++)
cout<<dp[i][j]<<" ";
}
for (int i = 0, l = strlen(s); i < l; i++)
if (dp[i][0] && store[i][0].length()) {
cout << "YES" << endl << store[i][0] << endl;
return 0;
}
cout << "NO" << endl;
return 0;
}