找出顺序表中连续最长的拿个数
#include <stdio.h> #include <stdlib.h> find(int num[], int n){ int max; int maxX; int i; int temp; int tempX; tempX = 0; temp = 1; max = 0; maxX = 0; for (i = 1; i < n; i++){ if (num[i] == num[tempX]){ temp++; } else{ if (temp > max){ max = temp; maxX = tempX; } temp = 1; tempX = i; } } printf("%d: %d", num[maxX], max); } main(){ int num[] = {3, 1, 2, 3, 4, 3, 3, 5, 6}; find(num, 9); }