Posted on 2008-06-02 22:02 
superman 阅读(714) 
评论(3)  编辑 收藏 引用  所属分类: 
ZOJ 
			 
			
		 
		 1 /* Accepted 1201 C++ 00:00.00 836K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n, x[100];
 9     
10     while(cin >> n && n)
11     {
12         char operation;
13         cin >> operation;
14         for(int i = 1; i <= n; i += 1)
15             cin >> x[i];
16         int ans[100] = { 0 };
17         if(operation == 'P')
18         {
19             int pos[100];
20             for(int i = 1; i <= n; i++)
21                 pos[x[i]] = i;
22             
23             for(int i = 1; i <= n; i++)
24                 for(int j = 1; j < pos[i]; j++)
25                     if(x[j] > i)
26                         ans[i]++;
27         }
28         if(operation == 'I')
29         {
30             for(int i = 1; i <= n; i++)
31             {
32                 int cnt = 0, j = 1;
33                 while(true)
34                 {
35                     if(ans[j] == 0)
36                         cnt++;
37                     if(cnt == x[i] + 1)
38                         break;
39                     j++;
40                 }
41                 ans[j] = i;
42             }
43         }
44         for(int i = 1; i <= n; i++)
45             cout << ans[i] << (i == n ? '\n' : ' ');
46     }
47     
48     return 0;
49 }
50