| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一次AC。。此题大爱啊。。算法:用一个堆栈把最近要匹配的括号的位置保存起来,然后同输入的位置相减就直接出来啦~
#include <stdio.h>
#define BUF 100
int main()
{
int Int_Stack[BUF] = {},s_ptr;
int now_in,now_state,n,m;
scanf("%d",&n);
while(n--)
{
int now_par = 0;
s_ptr = 0;
scanf("%d",&m);
for(int i = 1;i <= m;i ++)
{
scanf("%d",&now_in);
while(now_par <= now_in)
Int_Stack[++ s_ptr] = now_par ++;
printf("%d",now_in - Int_Stack[s_ptr-- ] + 1);
if(i != m)
putchar(' ');
}
printf("\n");
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator