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 bighead8116 at 2003-07-31 14:32:09 on Problem 1002
我的代码:
/* 
    PKU 1002 
    487-3279 
    By Bighead8116 
    Time : July 31st 2003 
    Quick Sort 
*/ 
#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
#include<assert.h> 

/*#define DEBUG*/ 
#define MAXN 100000 
#define MAXLEN 1000 

const int chars[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0}; 
long *datas; 

void read_in_data(FILE*,long); 
int cmp_func(const void *,const void *); 
void print_out(long sum); 

main() 
{ 
    long n; 
    FILE *fi,*fo; 

    #ifdef DEBUG 
        fi=fopen("input.txt","r"); 
        assert(fi!=NULL); 
    #else 
        fi=stdin; 
    #endif 

    fscanf(fi,"%ld",&n); 
    assert(n<=MAXN); 
    datas=(long *)calloc(n,sizeof(long)); 

    read_in_data(fi,n); 
    qsort(datas,n,sizeof(long),cmp_func); 
    print_out(n); 

    free(datas); 
    #ifdef DEBUG 
        fclose(fi); 
    #endif 
    return 0; 
} 

void read_in_data(FILE *fin,long sum) 
{ 
    char tmp[MAXLEN]; 
    long i,j,rst; 

    for(i=0;i<sum;i++){ 
        fscanf(fin,"%s",tmp); 
        rst=0; 
        for(j=0;j<strlen(tmp);j++){ 
            if((tmp[j]>='A') && (tmp[j]<='Z')) 
                rst=rst*10+chars[tmp[j]-'A']; 
            else if((tmp[j]>='0') && (tmp[j]<='9')) 
                rst=rst*10+tmp[j]-'0'; 
        } 
        *(datas+i)=rst; 
    } 
} 

int cmp_func(const void *a,const void *b) 
{ 
    long *x=(long *)a; 
    long *y=(long *)b; 

    if(*x==*y) 
        return 0; 
    if(*x>*y) 
        return 1; 
    return -1; 
} 

void print_out(long sum) 
{ 
    long i,j; 
    int have=0; 

    for(i=0;i<sum;){ 
        j=i+1; 
        while((datas[i]==datas[j]) && (j<sum)) 
            j++; 
        if(j-i>1){ 
            have=1; 
            printf("%ld-%ld %ld\n",datas[i]/10000,datas[i]%10000,j-i); 
        } 
        i=j; 
    } 
    if(!have) 
        printf("No duplicates.\n"); 
} 
我是快排的,自己弄的数据好好的,为什么……
WA了N次了,我快疯了……
大哥大姐们,帮忙啊
有测试数据的话COPY一份给我好不好啊
如果没有数据,那告诉我一下你们的解题思路也是可以的呀
这厢有礼了

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