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

这就是没读题的下场,100%经典WA代码

Posted by qingshenlwy at 2007-10-23 17:22:33 on Problem 1141
#include <iostream>
using namespace std;

int main(){
	int i,a1,a2,a3,a4,len;		//(1  )2  [3   ]4
	string str;
	a1=0;a2=0;a3=0;a4=0;
	cin>>str;
	len=str.length();
	for(i = 0 ;i < len; i++){
		if(str[i] == '(' ){
			if( a2 > 0 )		a2--;
			else a1++;}
		else if(str[i] == ')'){
			if( a1 > 0 )		a1--;
			else a2++;}
		else if(str[i] == '['){
			if( a4 > 0 )		a4--;
			else a3++;}
		else if(str[i] == ']'){
			if( a3 > 0 )		a3--;
			else a4++;}
	}
	for(i = 0 ; i < a2;i++)
		cout<<"(";
	for(i = 0 ; i < a4;i++)
		cout<<"[";
	cout<<str;
	for(i = 0 ; i < a1;i++)
		cout<<")";
	for(i = 0 ; i < a3;i++)
		cout<<"]";
	cout<<endl;
	cout<<a1+a2+a3+a4<<endl;
	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