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

出错的代码

Posted by hz02ruc at 2003-10-21 22:04:27 on Problem 1051
In Reply To:出错的代码你没交在这里啊 Posted by:hawk at 2003-10-21 21:37:27
void decode(char *code,int casenum)  
{  
  /***********************************************/
  /* char str[4*M],result[M],temp[N],numstr[M];  */
  /***********************************************/
    char *str=(char *)malloc(4*M);
    char *result=(char *)malloc(M);
    char *temp=(char *)malloc(N);
    char *numstr=(char *)malloc(M); //若用malloc则下面的numstr[j]值会变
    int codelen=strlen(code);  
    char *p;  
    int cur=0;  
    p=chrtocode(code[0]);  
    strcpy(str,p);  
    numstr[cur++]=strlen(p);  
    for(int i=1;i<codelen;i++)  
    {  
        p=chrtocode(code[i]);  
        int len=strlen(p);  
        strcat(str,p);  
        numstr[cur++]=len;  
    }  
    int k=0,n=0;  
    for(int j=cur-1;j>=0;j--)  
    {      
        memset(temp,'\0',N);        
        for(int s=0;s<numstr[j];s++) //在我的机子上numstr[j]的值会变!!(对sample input中最后一组数据) 
            temp[s]=str[k++];         
        result[n++]=codetochr(temp);  
    }  
    result[n]='\0';  
    printf("%d: %s\n",casenum,result);  
}  

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