|
|
вернуться в форумОбщий форумI always got a error of restricted functions!what's wrong!below is my code: #include "stdio.h" int Paritition(long array[],int begin,int end) { int i,j; long temp,temp2; temp=array[begin]; i=begin+1; j=end; while(1) { while(array[i]<temp) i++; while(array[j]>temp) j--; if(i>=j) break; temp2=array[i]; array[i]=array[j]; array[j]=temp2; } temp2=array[j]; array[j]=temp; array[begin]=temp2; return j; } void quicksorta(long array[],int begin,int end) { int iGenerate; if(begin<end) { iGenerate=Paritition(array,begin,end); quicksorta(array,begin,iGenerate-1); quicksorta(array,iGenerate+1,end); } } main() { int i,count; long a[20],extra; FILE *pf; pf=fopen("input.dat","r"); if(pf==NULL) { printf("File can't be opend!"); return; } fscanf(pf,"%d",&count); for(i=0;i<count;i++) fscanf(pf,"%ld",&a[i]); for(;i<20;i++); a[i]=0; fclose(pf); quicksorta(a,0,count-1); extra=a[count-1]; for(i=count-2;i>=0;i--) { if(extra>0) extra-=a[i]; else extra+=a[i]; } pf=fopen("output.dat","w"); fprintf(pf,"%ld",extra>=0?extra:-extra); } Re: I always got a error of restricted functions!what's wrong!below is my code: don't open file , use standard input/output here Re: I always got a error of restricted functions!what's wrong!below is my code: > don't open file , use standard input/output here |
|
|