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:分享一下我不存括号,不存p数组的思路 show my code

Posted by 20083331 at 2009-06-29 12:22:55 on Problem 1068 and last updated at 2009-06-30 07:45:33
In Reply To:分享一下我不存括号,不存p数组的思路 Posted by:deathado at 2008-05-31 17:20:35
不错,比我的方法好。我原来在你的基础上加了右括号的值



#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;


int main()
{
    short data[30];
    short str[100];
    int m;
    cin>>m;
    while(m--)
    {
        int index=0,n;
        cin>>n;
        data[0]=0;
        for(int i=1;i<=n;i++)
        {
            cin>>data[i];
            for(int j=1;j<=data[i]-data[i-1];j++)
            {
                str[index]=-2;
                index++;
            }
            str[index++]=-1;
        }        for(int i=0;i<index;i++)
        {
            if(str[i]==-1)
            {
                int result=1;
                for(int j=i-1;j>=0;j--)
                {
                    if(str[j]==-2)
                    {
                        str[j]=0;
                        str[i]=result;
                        if(i==index-1)
                            cout<<result;
                        else
                            cout<<result<<" ";
                        break;
                    }
                    else
                    {
                        result+=str[j];
                        str[j]=0;
                    }
                }
            }
        }

        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