|
|
back to boardhelp!!why my programme is wrong!i find no mistake in it! Posted by olive 5 May 2005 09:05 #include<stdio.h> int main(){ int stonenumber; int i,j; long int s=0,t=0,a[20],u,minweight; scanf("%d",&stonenumber); for(i=0;i<stonenumber;i++) scanf("%d",&a[i]); for(j=0;j<stonenumber-1;j++) for(i=0;i<stonenumber-j-1;i++) if(a[i]>a[i+1]) {u=a[i];a[i]=a[i+1];a[i+1]=u;} s=a[stonenumber-1]; t=a[stonenumber-2]; for(i=stonenumber-3;i>=0;i--) if(t<s||t==s) t=t+a[i]; else s=s+a[i]; if(s>t) minweight=s-t; else minweight=t-s; printf("%d",minweight); return 0; } please reply me:287662136@163.com Edited by author 05.05.2005 09:07 Edited by author 05.05.2005 09:07 Re: help!!why my programme is wrong!i find no mistake in it! Posted by beise 4 Oct 2006 12:52 5 2000 3 4 5 6 The correct answer should be 1988,and what's your answer? Re: help!!why my programme is wrong!i find no mistake in it! how can be the correct answer 1988 if we put one stone 2000 in then one heap and other stones (3+4+5+6=18) in then second heap? 2000-18=1982 not a 1988 Re: help!!why my programme is wrong!i find no mistake in it! Posted by hsejiv 27 Apr 2007 16:59 Can you explain your solution? I'm struck with test 5! Re: help!!why my programme is wrong!i find no mistake in it! yeah, my answer is 1982, but I have wrong answer on test 1 Re: help!!why my programme is wrong!i find no mistake in it! Posted by timur 24 Nov 2007 02:21 try this test: 5 3 3 2 2 2 the correct answer is 0. your program gives 2. Edited by author 24.11.2007 02:22 |
|
|