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

这麽简单的题都Wa且找不出错误....我想死...

Posted by Lucifer at 2005-08-31 00:27:05 on Problem 1690
#include <iostream.h>
#include <stdio.h>
#include <string.h>
using namespace std;
char s[300];
bool rightful(int j)
{
        if (j==0) return true;
        int i;
        i=j;
        bool its=false;
        for (;s[i]!=')';i++) if (s[i]=='+'||s[i]=='-') its=true;
        if (its==false) return true;
        i=j-1;
        for (;s[i]==' '&&i>=0;i--);
        if (i<0) return true;
        if (s[i]=='(') return true;
        if (s[i]=='+') return true;
        return false;
}
int deleteit(int j)
{
        int i;
        s[j]=' ';
        int t=0;
        for (i=j;i<strlen(s-1);i++)
        {
                if (s[i]==')'&&t==0) {s[i]=' '; return 0;}
                if (s[i]=='(') t++;
                if (s[i]==')') t--;
        }
        return 0;
}
int main()
{
        int n;
        scanf("%d\n",&n);
        for (int i=1;i<=n;i++)
        {
//                fgets(s,300,stdin);
                gets(s);
                int j;
                bool change;
                do
                {
                        change=false;
                        for (j=0;j<strlen(s); j++)
                        {
//                                if (s[j]==' '){ deleteit(j,1); change=true; break;       }
                                if (s[j]=='('&&rightful(j)) {deleteit(j); change=true; break;}

                        }
                } while(change==true);
//                puts(s);
                int q;
                for (q=0;q<strlen(s);q++)
                if (s[q]!=' ') cout<<s[q];
                cout<<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