题目链接:http://codeforces.com/problemset/problem/550/C
题意是给你一个不操过100位的数,问删除m位之后,问剩下的数不改变顺序能被8整除的数存在不存在;
能被8整除的数后三位一定能被8整除
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #define met(a, b) memset(a, b, sizeof(a)) using namespace std; #define N 115 #define INF 0x3f3f3f3f int slove(char s[]) { for(int i=0; s[i]; i++)///一位数; { int num = s[i]-'0'; if( num == 8 || num == 0 ) return num; } for(int i=0; s[i]; i++)///两位数; { for(int j=i+1; s[j]; j++) { int num = (s[i]-'0')*10 + (s[j]-'0'); if(num % 8 == 0) return num; } } for(int i=0; s[i]; i++)///三位数; { for(int j=i+1; s[j]; j++) { for(int k=j+1; s[k]; k++) { int num = (s[i]-'0')*100 + (s[j]-'0')*10 + (s[k]-'0'); if(num % 8 == 0) return num; } } } return -1; } int main() { char s[N]; while(scanf("%s", s) != EOF) { int ans = slove(s); if(ans == -1)puts("NO"); else printf("YES %d ", ans); } return 0; }