|
|
вернуться в форумWho can help,Why I am always crash!!!!!!!!!!!!! Послано kkk 15 май 2002 10:29 My programme as follows #include<stdio.h> #define N 32767 #define M 10000 main() { char a[32770]; int state,data; long n,k; state=0; for(k=0;k<=N;k++) a[k]=0; scanf("%ld",&n); for(k=0;k<n;k++) { scanf("%d",&data); if(data>=0&&a[data]!=1&&a[data]!=3)a[data]+=1; else if(data<0&&a[data]!=2&&a[data]!=3)a[-data-1]+=2; } scanf("%ld",&n); for(k=0;k<n;k++) { scanf("%d",&data); if(M-data>=0&&M-data<=N) { if(a[M-data]==1||a[M-data]==3) state=1; } else if(M-data<0&&M-data>=-N-1) { if(a[data-M-1]==2||a[data-M-1]==3) state=1; } } if(state)printf("YES"); else printf("NO"); } .....ZZZzzzz each element of the lists lays in the range from -32768 to 32767. I don't think your array A is large enough.... I still get crash Послано kkk 16 май 2002 11:02 My pro as follows #include<stdio.h> #define N 32767 #define M 10000 main() { char a[60000]; int state,data; long n,k; state=0; for(k=0;k<=40000;k++) a[k]=0; scanf("%ld",&n); for(k=0;k<n;k++) { scanf("%d",&data); if(data>=0) { if(a[data]!=1&&a[data]!=3) a[data]+=1; } else { if(a[data]!=2&&a[data]!=3) a[-data-1]+=2; } } scanf("%ld",&n); for(k=0;k<n;k++) { scanf("%d",&data); if(M-data>=0&&M-data<=N) { if(a[M-data]==1||a[M-data]==3) state=1; } else if(M-data<0&&M-data>=-N-1) { if(a[data-M-1]==2||a[data-M-1]==3) state=1; } } if(state)printf("YES"); else printf("NO"); } |
|
|