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

求助

Posted by gary88 at 2019-10-29 17:10:52 on Problem 2955
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int k1,k2,ans;
int main()
{
	char a[105];
	scanf("%s",&a);
	while(a[0]!='e')
	{
		k1=0;
		k2=0;
		ans=0;
		for(int i=0;;i++)
		{
			if(a[i]=='(')
			k1++;
			else if(a[i]=='[')
			k2++;
			else if(a[i]==')')
			{
				if(k1)
				{
					k1--;
					ans++;
				}
			}
			else if(a[i]==']')
			{
				if(k2)
				{
					k2--;
					ans++;
				}
			}
			else
			break;
			a[i]=0;
		}
		printf("%d\n",2*ans);
		scanf("%s",&a);
	}
}

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