289. 最长连续等差子数列-软件14

xiaoxiao2021-02-28  19

#include <iostream> #include <cstdio> using namespace std; int nums[100]; int main(int argc, char** argv) { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); scanf("%d", &nums[0]); if (N == 1) { printf("1\n"); continue; } scanf("%d", &nums[1]); int gap = nums[1] - nums[0]; int last = nums[1]; int maxLen = 2, len = 2; for (int i = 2; i < N; ++i) { int now; scanf("%d", &now); nums[i] = now; if (now - last == gap) ++len; else { if (len > maxLen) maxLen = len; gap = now - last; len = 2; } last = now; } if (len > maxLen) maxLen = len; printf("%d\n", maxLen); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2800291.html

最新回复(0)