ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1161. Stripies

Whats wrong with this code?
Posted by Sridhar 15 Mar 2009 18:48
#include <stdio.h>
#include <math.h>


#define NUM 100

// stripes # 1161
int main()
{
   int num;
   int weight[NUM];
   int i;
   int j;
  static  int k = 0;
   float coll[NUM];
   float temp;

    scanf("%d",&num);  // number of stripes

    for ( i = 0 ; i <= num ; i++)
    {
       if ( i == num) weight[i] = 1;  // end of the array
       else
       scanf("%d",&weight[i]);   // input the weight of the stripes
     } // end of for loop

     for ( i = 0 ; i < num-1 ; i++)
     {
       for  ( j = i+1 ; j < num; j++)
       {
        coll[k] = 2 * sqrt( weight[i] * weight[j]);  // calculate the collision weights
        k++;
       }
    }

/*for ( i = 0 ; i < k ; i++)
{
  printf("\n%f",coll[i]);
 }*/

   for(i=0 ; i < num; i++)   // sort the array
  {
     for ( j = i+1 ; j <= num ; j++)
     {
        if (coll[i] > coll[j] )
        {
           temp = coll[i];
           coll[i] = coll[j];
           coll[j] = temp;
         } //  end of if
   }  // end of j for loop
   }  // end of i for loop

/*for ( i = 0 ; i < k ; i++)
 {
     printf("\n%.2f\n", coll[i]);
  } */

   printf("\n\n%.2f\n",coll[0]);  // print the least value
     return 0;

     } // end of main


Sometimes the array is not getting sorted
can anyone tell me why?

Help needed.....