Posted on 2008-05-25 17:41
superman 阅读(491)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1016 C++ 00:00.00 832K */
2 #include <cstdio>
3 #include <string>
4 #include <iostream>
5
6 using namespace std;
7
8 int main()
9 {
10 int n;
11 cin >> n;
12 while(cin >> n)
13 {
14 string seq;
15
16 int p[100] = {0};
17 for(int i = 1; i <= n; i++)
18 {
19 cin >> p[i];
20 for(int j = 1; j <= p[i] - p[i - 1]; j++)
21 seq += '(';
22 seq += ')';
23 }
24 bool x[100] = {0};
25 for(int i = 0; i < seq.size(); i++)
26 if(seq[i] == ')')
27 {
28 int count = 0;
29 for(int j = i - 1; j >= 0 ; j--)
30 if(seq[j] == '(')
31 {
32 count++;
33 if(x[j] == 0)
34 {
35 cout << count << (i == seq.size()- 1 ? '\n' : ' ');
36 x[j] = 1;
37 break;
38 }
39 }
40 }
41 }
42
43 return 0;
44 }
45