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

Why wa ,please help

Posted by steve_cys at 2007-01-02 16:00:43 on Problem 1577
#include<iostream>
#include<cstring>
using namespace std;
struct tab
{
   int num;
   int next;
};
struct node
{
   char s;
   int tag;
   int lev;
};
int main()
{
    tab count[100];
    char input[100][100];
    int nextset=1;
    while(nextset)
    {
        int t=0;
        cin.getline(input[t],100);
        while(input[t][0]!='*'&&input[t][0]!='$')
        {
           count[t].num=strlen(input[t]);
           count[t].next=0;
           t++;
           cin.getline(input[t],100);
        }
        t--;
        if(t!=-1)
        {
            node stack[100];
            int top=-1;
            stack[++top].s=input[t][0];
            stack[top].tag=1;
            stack[top].lev=t;
            cout<<stack[top].s;
            while(top!=-1)
            {
                if(stack[top].tag==1)
                {
                    if(stack[top].lev==0)
                    {
                        top--;
                        if(top!=-1)stack[top].tag++;
                    }
                    else
                    {
                        int m=stack[top].lev-1,ok=0;
                        for(;m>=0;m--)
                        {
                           int j;
                           for(j=count[m].next;j<count[m].num;j++)
                           {
                              if(input[m][j]<stack[top].s)
                              {
                                 stack[++top].s=input[m][j];
                                 stack[top].tag=1;
                                 stack[top].lev=m;
                                 cout<<stack[top].s;
                                 ok=1;
                                 count[m].next=j+1;
                                 //cout<<m<<' '<<j+1<<endl;
                                 break;
                              }
                           }
                           if(ok)break;
                        }
                        if(!ok)stack[top].tag++;
                    }
                }
                else if(stack[top].tag==2)
                {
                     if(stack[0].tag==1)
                     {
                        int m=stack[top].lev-1,ok=0;
                        for(;m>=0;m--)
                        {
                           int j;
                           for(j=count[m].next;j<count[m].num;j++)
                           {
                              if(input[m][j]>stack[top].s&&input[m][j]<stack[0].s)
                              {
                                 stack[++top].s=input[m][j];
                                 stack[top].tag=1;
                                 stack[top].lev=m;
                                 cout<<stack[top].s;
                                 ok=1;
                                 count[m].next=j+1;
                                 //cout<<m<<' '<<j+1<<endl;
                                 break;
                              }
                           }
                           if(ok)break;
                        }
                        if(!ok)stack[top].tag++;
                     }
                     else if(stack[0].tag==2)
                     {
                        int m=stack[top].lev-1,ok=0;
                        for(;m>=0;m--)
                        {
                           int j;
                           for(j=count[m].next;j<count[m].num;j++)
                           {
                              if(input[m][j]>stack[top].s)
                              {
                                 stack[++top].s=input[m][j];
                                 stack[top].tag=1;
                                 stack[top].lev=m;
                                 cout<<stack[top].s;
                                 ok=1;
                                 count[m].next=j+1;
                                 //cout<<m<<' '<<j+1<<endl;
                                 break;
                              }
                           }
                           if(ok)break;
                        }
                        if(!ok)stack[top].tag++;
                     }
                }
                else if(stack[top].tag==3)
                {
                     top--;
                     if(top!=-1)stack[top].tag++;
                }
            }
            cout<<endl;
        }
        else cout<<endl;
        if(input[t+1][0]=='$')nextset=0;
    }
    //system("pause");
    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