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

Обсуждение задачи 1025. Демократия в опасности

accepted C#
Послано Vladimir Kharchenko 23 дек 2014 00:24
using System;


namespace exercizes
{
    class Democracy
    {

        public static void Main()
        {
            int Iskomoe = 0;

            int numGroups = Int16.Parse(Console.ReadLine());
            string[] populate = Console.In.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

            int[] PopulatesInGroups = ParsingPiG(populate);

            Sort(ref PopulatesInGroups);

            for (int i = 0; i <= PopulatesInGroups.Length/2; i++)
            {
                Iskomoe += PopulatesInGroups[i]/2 + 1;
            }

            Console.WriteLine(Iskomoe);
            //Console.ReadKey();

        }

        private static int[] ParsingPiG(string[] populate)
        {
            int[] PiG = new int[populate.Length];

            for (int i = 0; i < populate.Length; i++)
            {
                PiG[i] = Int16.Parse(populate[i]);
            }
            return PiG;
        }



        private static void Sort(ref int[] popingroups)
        {
           for (int i=1; i < popingroups.Length; i++)
            {
               int key = popingroups[i];
               int j = i - 1;

               while (j >= 0 && popingroups[j] > key)
               {
                   popingroups[j+1] = popingroups[j];
                   j = j - 1;
               }
               popingroups[j + 1] = key;
            }
        }

    }
}
Re: accepted C#
Послано Sertmon 9 янв 2016 17:16
//a shorter version

using System;
using System.Linq;

namespace _1025
{
    class Program
    {
        static void Main(string[] args)
        {
            double Result = 0;
            int n = int.Parse(Console.ReadLine());
            var numbers = Console.ReadLine().Split(' ').Select(token => int.Parse(token));
            int[] arr = numbers.ToArray();

            Array.Sort(arr);
            double numbOfGroups =  Math.Ceiling(arr.Length/2.0);

            for (int i = 0; i < numbOfGroups; ++i)
            {
                Result += (Math.Ceiling(arr[i] / 2.0));
            }
            Console.WriteLine(Result);
        }
    }
}

Edited by author 09.01.2016 17:17