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 |
我的结果是对的,为什么说是wrong answer呢?#include <stdio.h> int dividable(int* a) { int sum = a[0]+a[1]+a[2]+a[3]+a[4]+a[5]; if(sum % 2) return 0; /* odd sum */ int hsum = sum / 2; /* half sum */ int i,j,k; /* check whether we could find some numbers so that they add up to hsum */ /* 1 number only */ i=0; while(i<6){ if(a[i]==hsum) return 1; i++; } /* 2 numbers */ i=0; while(i<6){ j=i+1; while(j<6){ if(a[i]+a[j]==hsum) return 1; j++; } i++; } /* 3 numbers */ i=0; while(i<6){ j=i+1; while(j<6){ k=j+1; while(k<6){ if(a[i]+a[j]+a[k]==hsum) return 1; k++; } j++; } i++; } /* 4 numbers are identical to 2 numbers */ /* 5 numbers are identical to 1 number only */ return 0; } int main(int argc, char * argv[]) { int a[6]; int i=1; while(1){ scanf("%d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]); if(a[0]==0 && a[1]==0 && a[2]==0 && a[3]==0 && a[4]==0 && a[5]==0) break; printf("Collection #%d:\n",i); if(dividable(a)) printf("Can be divided.\n\n"); else printf("Can't be divided.\n\n"); i++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator