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 huxm3 at 2003-08-18 16:44:25 on Problem 1002
我在tc2中运行说数组的范围太大,但是在vc运行又没错。
提交后又说runtime erro.真不知道咋搞的。

源程序:

#include "stdio.h"
#include "math.h"
#define N 100000
long int a[N];

long a2i(str)
char str[];
{
 int i,j,d;
 long int n;
 n=0;i=0;j=0;
 while(j<7){
     switch(str[i++]){
         case 'A':
         case 'B':
         case 'C': d=2;break;
         case 'D':
         case 'E':
         case 'F': d=3;break;
         case 'G':
         case 'H':
         case 'I': d=4;break;
         case 'J':
         case 'K':
         case 'L': d=5;break;
         case 'M':
         case 'N':
         case 'O': d=6;break;
         case 'P':
         case 'R':
         case 'S': d=7;break;
         case 'T':
         case 'U':
         case 'V': d=8;break;
         case 'W':
         case 'X':
         case 'Y': d=9;break;
         case '0':
         case '1':
         case '2':
         case '3':
         case '4':
         case '5':
         case '6':
         case '7':
         case '8':
	 case '9': d=str[i-1]-'0';break;
       default:
             d=-1;break;
       }
     if(d!=-1){
        j++;
        n=n*10+d;
       }
   }
return n;
}
 
void qsort(c,left,right)
long int c[];
int left,right;
{ 
    int le,b;
    long int t,t1;
    if (left<right)
    { 
        le=left;
        for (b=le+1;b<=right;b++)
            if ((c[b]<c[left]) && b!=++le)
            { 
                t=a[le]; 
                c[le]=c[b]; 
                c[b]=t; 
            } 
                t1=c[le];
                c[le]=c[left];
                c[left]=t1;
       qsort(c,left,le-1);
       qsort(c,le+1,right);
    }
}


main()
{
 char str[20];
 int i,n;
 long int m;
 int time=1,flag=0;
 scanf("%d",&n);
 for(i=0;i<n;i++){
    scanf("%s",str);
    a[i]=a2i(str);
    }
 qsort(a,0,n-1);
 m=a[0];
 for(i=1;i<n;i++) {
    if(m!=a[i]) {
         if(time>1){
               flag=1,printf("%d",m/10000),printf("-");
               printf("%d",m%10000);
               printf(" ");
               printf("%d\n",time);
              }
         m=a[i];
         time=1;
        }
    else {
         time++;
         if(time>1&&i==n-1){
               flag=1,printf("%d",m/10000),printf("-");
               printf("%d",m%10000);
               printf(" ");
               printf("%d\n",time);
              }
          }
   }
  if(flag==0) printf("No duplication.");
 }

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