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:小弟总是WA啊,希望各位路过的大侠帮忙看下代码,注释比较详细的,谢谢了,出门靠朋友嘛

Posted by OUmaster at 2007-02-27 09:22:35 on Problem 1002
In Reply To:小弟总是WA啊,希望各位路过的大侠帮忙看下代码,注释比较详细的,谢谢了,出门靠朋友嘛 Posted by:OUmaster at 2007-02-27 00:42:47
> #include <stdio.h>
> #include <stdlib.h>
> 
> int map(char ch)
> {
>     if(ch=='0')
>         return 0;
>     else if(ch=='1')
>         return 1;
>     else if(ch=='A' || ch=='B' || ch=='C' || ch=='2')
>         return 2;
>     else if(ch=='D' || ch=='E' || ch=='F' || ch=='3')
>         return 3;
>     else if(ch=='G' || ch=='H' || ch=='I' || ch=='4')
>         return 4;
>     else if(ch=='J' || ch=='K' || ch=='L' || ch=='5')
>         return 5;
>     else if(ch=='M' || ch=='N' || ch=='O' || ch=='6')
>         return 6;
>     else if(ch=='P' || ch=='R' || ch=='S' || ch=='7')
>         return 7;
>     else if(ch=='T' || ch=='U' || ch=='V' || ch=='8')
>         return 8;
>     else if(ch=='W' || ch=='X' || ch=='Y' || ch=='9')
>         return 9;
>     else return -1;
> }
> 
> int convert(char s[100]){//把输入字符串转换为数字 
>        int i=0;
>        int number=0,k=1000000;
> 
>        while(s[i]!='\0'){
>            if(map(s[i])!=-1){number+=k*map(s[i]);k/=10;}
>            ++i;
> 
>        }
>        return number;
> }
> 
> int partition(int *L,int low,int high)
> {
>     int key;
>     L[0]=L[low];
>     key=L[low];
>     while(low<high){
>         while(low<high && L[high]>=key)--high;
>         L[low]=L[high];
>         while(low<high && L[low]<=key)++low;
>         L[high]=L[low];  
>         }
>      L[low]=L[0];
>      return low;    
> }
> 
> void Qsort(int *L,int low,int high)//快速排序 
> {
>     int loc;
>     if(low<high){
>         loc=partition(L,low,high);
>         Qsort(L,low,loc-1);
>         Qsort(L,loc+1,high);
>         }
> }
> 
> main()
> {
>    char ss[100],gg[8];
>    int *cc,n,i,j,k=0,num=1;
>    scanf("%d",&n);
>    cc=(int *)malloc((n+1)*sizeof(int));
>    for(i=0;i<=n;++i)
>         cc[i]=0;
>    for(i=1;i<=n;++i){
>        scanf("%s",ss);    
>        cc[i]=convert(ss);
>    }
>    Qsort(cc,1,n);//排好顺序 
>    printf("\n");
>    for(i=1;i<=n;++i){//输出 
>        if(cc[i]==cc[i+1])num++;
>        if(num>1 && cc[i]!=cc[i+1])
>           {
>               itoa(cc[i],gg,10);//把数字换为字符 
>               if(cc[i]/1000000!=0){
>                 for(j=0;j<3;++j)
>                   printf("%c",gg[j]);
>                 printf("-");
>                 for(j=3;j<=6;++j)
>                   printf("%c",gg[j]);
>                 printf(" %d\n",num);
>                }
>                else {//首位为0的情况 
>                 printf("0");
>                 for(j=0;j<2;++j)
>                   printf("%c",gg[j]);
>                 printf("-");
>                 for(j=2;j<6;++j)
>                   printf("%c",gg[j]);
>                 printf(" %d\n",num);
>                }   
>               num=1;
>               if(k==0)k=1;          
>           }
>    }
>    if(k==0)printf("No duplicates");
>    
>    getch();
> }

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