#include <stdio.h> #include <stdlib.h> typedef unsigned int size_t; void *subarray(const int *array, size_t count) { size_t i, j; size_t numb, max = 0; const int *tmp; int *res; for (i = 0; i < count - 1; ++i) { /* code */ tmp = array + i; numb = 0; for (j = 0; j < count - i; ++j) { /* code */ if (*(tmp + (j + 1)) - *(tmp + j) != 1) { /* code */ break; } numb++; } if (numb > max) { /* code */ max = numb; res = tmp; } } printf("The longest subarray is: "); for (i = 0; i < max + 1; ++i) { /* code */ printf("%d ", *(res + i)); } } int main(int argc, char const *argv[]) { /* code */ int array[] = {1, 3, 4, 5, 6, 9, 10}; subarray(array, 7); return 0; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务