|  | 
|  | 
| вернуться в форум | [Test #5] why always stuck at test #5 I don't know what happen with my code.I alway stuck at test#5.
 Could everybody give me some suggest?
 
 This is my code :
 #include<stdio.h>
 #include<stdlib.h>
 
 int main(){
 
 int weight[20];
 int stone_bag_num,i,temp,j,temp_group,group1,group2;
 
 
 scanf("%d",&stone_bag_num);
 /*  printf("\nstone bag : %d\n",stone_bag_num); */
 
 
 /* init weight */
 for (i = 0 ; i < stone_bag_num;i++){
 weight[i]=0;
 }
 
 
 /* input number  */
 for(i = 0 ; i < stone_bag_num ; i++){
 scanf("%d",&weight[i]);
 /*    printf("\nThe bag : %d  weight : %d\n",i,weight[i]); */
 }
 
 /*  put the big weigth into bag 1 */
 
 for (i = 0 ; i < stone_bag_num ; i++ ){
 for (j= i+1 ; j < stone_bag_num ; j++ ){
 if ( weight[i] < weight[j] ){
 temp = weight[i];
 weight[i] = weight[j];
 weight[j] = temp;
 }
 }
 
 }
 
 /*
 printf("flag");
 for (i = 0 ; i < stone_bag_num ; i++ ){
 printf("The bag : %d weight : %d\n",i,weight[i]);
 }
 */
 
 
 /* calcate the mid */
 group1=0,group2=0;
 for (i = 0 ; i < stone_bag_num ; i++ ){
 temp_group = (   (   group1+group2   ) /2   );
 if(     (group1 - temp_group)  >  (group2 - temp_group)   ){
 group2=group2+weight[i];
 }
 else
 group1=group1+weight[i];
 
 }
 
 /* printf("group1 : %d  group2 : %d",group1,group2); */
 
 if(  (group1 - group2) > 0){
 printf("%d",abs(group1 - group2)  );
 }
 else{
 printf("%d",abs(group2 - group1)  );
 }
 exit(0);
 /*return 0;*/
 
 }
 
 | 
 | 
|