http://poj.org/problem?id=1068
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int a[101],b[102],v[101]; 6 int t,n; 7 scanf("%d",&t); 8 while(t--) 9 { 10 scanf("%d",&n); 11 memset(a,0,sizeof(a)); 12 for (int i = 1; i <= n; i++) 13 { 14 scanf("%d",&a[i]); 15 } 16 int o = 0; 17 for (int i = 1; i <= n; i ++) 18 { 19 int k = a[i]-a[i-1]; 20 if(k > 0) 21 { 22 while(k--) 23 { 24 v[o++] = 0; 25 } 26 v[o++] = 1; 27 } 28 else if (k==0) 29 { 30 v[o++] = 1; 31 } 32 33 } 34 int tt = 0,j,p; 35 for (int i = 0; i < o; i ++) 36 { 37 int cnt = 0; 38 if(v[i]==1) 39 { 40 for (j = i-1; j >= 0; j --) 41 { 42 if (v[j]==0) 43 { 44 v[j] = -1; 45 break; 46 } 47 } 48 for (p = j; p <= i; p ++) 49 { 50 if(v[p]==1) 51 ++cnt; 52 } 53 b[tt++] = cnt; 54 } 55 } 56 printf("%d",b[0]); 57 for (int i = 1; i < tt; i ++) 58 printf(" %d",b[i]); 59 puts(""); 60 } 61 return 0; 62 }