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 1025. Democracy in Danger

accepted C#
Posted by Vladimir Kharchenko 23 Dec 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#
Posted by Sertmon 9 Jan 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