Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一次AC。。此题大爱啊。。

Posted by Web_Board at 2011-02-09 23:20:02 on Problem 1068
算法:用一个堆栈把最近要匹配的括号的位置保存起来,然后同输入的位置相减就直接出来啦~
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator