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

为 什么会 出现 错误呢 ?someone helps!~

Posted by __sunshine at 2008-10-21 20:26:27 on Problem 1141
#include <cstdlib>
#include <iostream>

using namespace std;

char an[105];
int cn[105],n;

inline bool check(char a,char b){
     if(a=='('&&b==')')return true;
     if(a=='['&&b==']')return true;
     return false;
}

bool angle(int a){
     if(a==n-1)return false;
     for(int i=(cn[a]!=-1)?(cn[a]+1):a+1;i<n;i++){
             if(cn[i]!=-1&&(an[i]==')'||an[i]==']')){
                         if(angle(cn[i])==false)
                         return false;
                         cn[i]=-1;
             }
             if(check(an[a],an[i])==true){
                       cn[i]=a;
                       cn[a]=i;
                       return true;
             }
     }
     return false;
}

void print(int i){
     if(an[i]=='('||an[i]==')'){
                 printf("()");
                 return ;
     }
     if(an[i]=='['||an[i]==']'){
                 printf("[]");
                 return ;
     }
}
                                

int main(int argc, char *argv[])
{
    while(gets(an)){
             memset(cn,-1,sizeof(cn));
             n=strlen(an);
             
             for(int i=0;i<n;i++){
                     if(an[i]==')'||an[i]==']')continue;
                     angle(i);
             }
             
             for(int i=0;i<n;i++){
                     if(cn[i]!=-1)printf("%c",an[i]);
                     else print(i);
             }
             printf("\n");
    }
         
    system("PAUSE");
    return EXIT_SUCCESS;
}

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