ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1161. Stripies

Sridhar Whats wrong with this code? // Задача 1161. Stripies 15 мар 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.....