#include <stdio.h> #include <string.h> bool vis[11]; int n, k; bool judge(int x) { memset(vis, false, sizeof(vis)); if (x == 0) vis[0] = true; while (x) { vis[x%10] = true; x /= 10; } for (int i = 0; i <= k; i++) if (vis[i] == false) return false; return true; } int main() { int x; while (scanf("%d %d", &n, &k) != EOF) { int ans = 0; for (int i = 1; i <= n; i++) { scanf("%d", &x); if (judge(x)) ans++; } printf("%d ", ans); } return 0; }
B,求序列中最长满足斐波那契性质的序列长度。
#include <stdio.h> int a[100005]; int main() { int n; while (scanf("%d", &n) != EOF) { int ans = 0; int len = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (i > 2) { if (a[i] == a[i-1] + a[i-2]) { len++; if (len > ans) ans = len; } else { len = 0; } } } if (n < 2) printf("%d ", n); else printf("%d ", ans+2); } return 0; }