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 goingeast at 2011-06-30 21:24:39 on Problem 1068
In Reply To:根据面向对象的思想,把括号表示出来才是王道。 Posted by:pclimbing at 2010-08-02 11:59:44
> 先存括号,再操作。
> 我看到有许多高人用种种方法攻克此题,但我还是坚持吾道。
呃,给你的代码 AC的。就用你说的。。
#include<stdio.h>
int main(){
    int data,n,i,j,w,pCode[20],wCode[20];
    char p[40];
    scanf("%d", &data);
    while(data--){
//-------------------------------------        
        scanf("%d",&n);
        for(i=0; i<n; ++i){
            scanf("%d",&pCode[i]);
            }
//--------------------------------------            
       for(i=0; i<n; ++i){
            if(i==0){
                for(j=0; j<pCode[0]; ++j){
                    p[j]='(';     
                }     
                p[j]=')';
            }else if(pCode[i]>pCode[i-1]){
                int t1,t;
                t1= pCode[i]-pCode[i-1];
                for(t=0; t<t1; ++t){
                    p[++j]='(';
                    }
                p[++j]=')';    
            }else if(pCode[i]==pCode[i-1]){
                p[++j]=')';
                }          
            }            
        
        for(i=0; i<2*n; ++i){
            printf("%c",p[i]);
            }
        printf("\n"); 
        w=0;             
//------------------------------------------
        for(i=0; i<2*n; ++i){
            
            if(p[i]==')'){
                int k,flag=0;
                for(k=i; k>=0;--k){

                    if(p[k]=='('){
                        wCode[w++]=(flag+1)/2;
                        p[k]=0;
                        k=-1;
                        }else{
                            flag++;
                            }
                    }        
                }                
            }
               
        for(i=0; i<n; ++i){
            printf("%d ",wCode[i]);
            }
        printf("\n");
//------------------------------------------                
            }
                                   
    system("pause");        
    }

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