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

改进了好几个地方,可总是RE,是不是数组作形参造成的?高手帮忙看一下

Posted by XBR at 2006-06-29 09:16:46 on Problem 1400
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
#define MAX 251
int n,len;
int Operator(char s)
{
    if (s=='+'||s=='-'||s=='*'||s=='/') return 1;
    else return 0;
}
int FindChar(int p,char s[],char &lc,char &rc)
{
    int tp;
   
    if ((p>=0)&&(p<len))
                {
                      tp=p;
                      while(1){
                            if (tp>=0) 
                            {
                                if ((s[tp-1]=='(')||(s[tp-1]==')')) {lc='#';break;}
                                if (Operator(s[tp])) {lc=s[tp];break;}
                                else tp--;
                            }    
                            else {lc='#';break;}
                      }    
                      tp=p;
                      while(1){
                          if (tp<len)
                          {
                              if ((s[tp+1]=='(')||(s[tp+1]==')')) {rc='#';break;}
                              if (Operator(s[tp])) {rc=s[tp];break;}
                              else tp++;
                          }    
                          else {rc='#';break;}
                      }
                      return 1;
                  }
     else return 0;      
 }
 
int Cancel(char a,char b,char c,char d)
{
    int flag1,flag2;
    if ((a=='+')||(a=='-'&&(b=='*'||b=='/'))||(a=='*'&&(b=='*'||b=='/'))||a=='#'||b=='#') flag1=1;
    else flag1=0;
    if ((c=='+'&&(d=='+'||d=='-'))||(c=='-'&&(d=='+'||d=='-'))||c=='*'||c=='/'||c=='#'||d=='#') flag2=1;
    else flag2=0;
    if ((flag1==1)&&(flag2==1)) return 1;
    else return 0;
}    
    
int Parentheses(char s[])
{
    int p=0,pl,pr;
    char lc1=' ',rc1=' ',lc2=' ',rc2=' ';
    while(s[p]!='\0')
    {
        if (s[p]==')') {
            pr=p;
            FindChar (pr,s,lc2,rc2);
            while(s[p]!='(') p--;
            pl=p;
            FindChar (pl,s,lc1,rc1); 
            if (Cancel(lc1,rc1,lc2,rc2)) {s[pr]='0';s[pl]='0';}
            else {s[pr]='>';s[pl]='<';}
        }
        p++;
    }
    return 1;
}            
              
                      
int main()
{
    char str[N][MAX];
    int i,j;   
    scanf("%d",&n);
    for (i=0;i<n;i++){
        scanf("%s",str[i]);
        if (strlen(str[i])>251) return -1;
    }    
    for (i=0;i<n;i++)
    {
        len=strlen(str[i]);
        Parentheses(str[i]);
        j=0;
        
        while(str[i][j]!='\0'){
            if (str[i][j]=='<') str[i][j]='(';
            if (str[i][j]=='>') str[i][j]=')';
            if (str[i][j]!='0') printf("%c",str[i][j]);
            j++;
        }
        printf("\n");
    }
    system("PAUSE");
    return 1;
}           

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