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 |
有没有大牛给解释一下啊??In Reply To:全部输入后再一个个检查就WA,一边输入一边检查等到找到合适的数据就退出程序的就AC Posted by:oeym at 2006-02-25 23:01:32 > WA的程序: > > #include <stdio.h> > #include <stdlib.h> > > int cmp(const void *a, const void *b) > { > return *(int *)a - *(int *)b; > } > > int main() > { > > int a[50000], b[50000], la, lb, i, j, tmp, *p; > > scanf("%d", &la); > > for (i = 0; i < la; i++) > { > scanf("%d", &a[i]); > } > > scanf("%d", &lb); > > for (i = 0; i < lb; i++) > { > scanf("%d", &b[i]); > } > > qsort(a, la, sizeof(a[0]), cmp); > > for (i = 0; i < lb; i++) > { > tmp = 10000 - b[i]; > p = (int *) bsearch(&tmp, a, la, sizeof(a[0]), cmp); > if (p != NULL) > { > printf("YES\n"); > break; > } > } > if (i == lb) > { > printf("NO\n"); > } > return 0; > } > > AC的程序: > > #include <stdio.h> > #include <stdlib.h> > > int cmp(const void *a, const void *b) > { > return *(int *)a - *(int *)b; > } > > int main() > { > > int a[50000], bi, la, lb, i, j, tmp, *p; > > scanf("%d", &la); > > for (i = 0; i < la; i++) > { > scanf("%d", &a[i]); > } > > scanf("%d", &lb); > > for (i = 0; i < lb; i++) > { > scanf("%d", &bi); > tmp = 10000 - bi; > p = (int *) bsearch(&tmp, a, la, sizeof(a[0]), cmp); > if (p != NULL) > { > printf("YES\n"); > return 0; > } > } > > printf("NO\n"); > return 0; > } > > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator