#include<stdio.h> #define max 100000 typedef struct node { int a[max]; }list; int main() { int n; list p; scanf_s("%d", &n); int i = 0; for (i = 0;i < n;i++) { scanf_s("%d", &p.a[i]); } int maxp = 0, maxlen = 1;//最长子列的起始位置及其长度 int len = 1, position = 0;//最初长度至少为1,位置为0 for (i = 1;i < n;i++) {//从1开始是为了n=1的情况 if (p.a[i - 1] >= p.a[i]) { if (len > maxlen) { position = i; maxlen = len; maxp = position - maxlen; } len = 1; } else { len++; } } if (len > maxlen) { maxlen = len; maxp = i - maxlen; }//全顺序的情况 for (int j = maxp;j < (maxp + maxlen);j++) { if (j == maxp)printf("%d", p.a[j]); else printf(" %d", p.a[j]); } return 0; }
我用的是vs,所以提交的时候注意改一下scanf_s,OK!!