• 2018-03-01
• 1,020
• 0
• 0

A strange number

Time Limit: 1s

Description

Given a positive integer with a maximum of 100 digits, ask if you can remove several bits (removing zero bit is also okay) from it, so that the modified number can be divisible by 8.

Input

The input consists of multiple test cases. Each test case contains a positive integer with a maximum of 100 digits.

Output

Print “YES” if you can complete the given question.
Print “NO” if you can’t.

```1234
3354
6789```

```YES
NO
YES```

Solution

``````#include <bits/stdc++.h>
using namespace std;

void find(char num[])
{
for (int k = 0; k < strlen(num); ++k)
{
if ((num[k]-48) % 8 == 0)
{
printf("YES\n");
return;
}
}

for (int j = 0; j < strlen(num); ++j)
for (int k = j + 1; k < strlen(num); ++k)
{
if (((num[j]-48)*10 + (num[k]-48)) % 8 == 0)
{
printf("YES\n");
return;
}
}

for (int i = 0; i < strlen(num); ++i)
for (int j = i + 1; j < strlen(num); ++j)
for (int k = j + 1; k < strlen(num); ++k)
{
if (((num[i]-48)*100 + (num[j]-48)*10 + (num[k]-48)) % 8 == 0)
{
printf("YES\n");
return;
}

}
printf("NO\n");
}

int main()
{
char num[105];
while (~scanf("%s", num))
{
find(num);
}

return 0;
}
``````