这个整除36的与整除45的完全一样,就是被4整除的有点多,但都是两位数,所以枚举后面两位就可以了.
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; const int N = 1005; const int M = 15; const int dir[30][2] = { {0, 0}, {4, 0}, {8, 0}, {1, 2}, {1, 6}, {2, 0}, {2, 4}, {2, 8}, {3, 2}, {3, 6}, {4, 4}, {8, 4}, {5, 2}, {5, 6}, {6, 0}, {6, 4}, {6, 8}, {7, 2}, {7, 6}, {8, 8}, {9, 2}, {9, 6} }; int tmp, rec[M], cnt[M]; int n, s[N], x, id; bool flag; char ans[N]; void init() { char num[N]; scanf("%s", num); x = strlen(num), tmp = 0; flag = false; memset(rec, 0, sizeof(rec)); memset(ans, 0, sizeof(ans)); for (int i = 0; i < x; i++) { int cur = num[i] - '0'; tmp += cur; rec[cur]++; } } void put(int a[], int d, char *str) { int len = 0; for (int i = 9; i >= 0; i--) { for (int j = 0; j < a[i]; j++) str[len++] = i + '0'; } for (int i = 0; i < 2; i++) str[len++] = dir[d][i] + '0'; str[len] = '