Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
个位高手,怎么我老“runtime error" 呀。(请您看一下代码,我的基本思路,基数排序,然后判断重复)#include<iostream.h> int n,**numbers,**t; char In[20]; void CountSort(int **A,int d){ int i,j,digits[10]; for(i=0;i<10;i++)digits[i]=0; for(i=0;i<n;i++) digits[A[i][d]]++; for(i=1;i<10;i++) digits[i]+=digits[i-1]; for(i=n-1;i>=0;i--){ digits[A[i][d]]--; for(j=0;j<7;j++)t[digits[A[i][d]]][j]=A[i][j]; } for(i=0;i<n;i++) for(j=0;j<7;j++)A[i][j]=t[i][j]; } void RadixSort(int **A){ for(int d=6;d>=0;d--) CountSort(A,d); } inline int map(char a){ if(a-'0'<10)return a-'0'; else if((int)a<=80)return 2+((int)a-'A')/3; else return 2+((int)a-1-'A')/3; } void Put(int A[]){ int i,k=0; cin>>In; for(i=0;In[i]!='\0';i++) if(In[i]=='-')continue; else A[k++]=map(In[i]); } void init(){ int i; cin>>n; t=new int*[n]; numbers=new int*[n]; for(i=0;i<n;i++){ t[i]=new int[7]; numbers[i]=new int[7]; Put(numbers[i]); } } bool equal(int A[],int B[]){ for(int i=0;i<7;i++) if(A[i]!=B[i])return false; return true; } void Out(int A[]){ cout<<A[0]; cout<<A[1]; cout<<A[2]; cout<<'-'; cout<<A[3]; cout<<A[4]; cout<<A[5]; cout<<A[6]; } void judge(){ int counter,i,j; bool is=true; for(i=0;i<n-1;i++){ if(equal(numbers[i],numbers[i+1])){ is=false; Out(numbers[i]); counter=0;j=i; while(equal(numbers[j],numbers[i])&&j<n){ j++; counter++; } cout<<' '<<counter<<endl; i=j-1; } } if(is==true) cout<<"No duplicates."<<endl; } void finish() { for(int i=0;i<n;i++){ delete[] numbers[i]; delete[] t[i]; } delete[] numbers; delete[] t; } int main(){ init(); RadixSort(numbers); judge(); finish(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator