CCCPaste

Antypolski Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithms05
{
    class Program
    {
        static void zad1()
        {
            int[] mandaty;
            int[] glosy;
            float[] calcTab;
            float max;
            int groupCount, mandatesCount, maxInd = 0;

            Console.Write("Podaj liczbe partii: ");
            groupCount = int.Parse(Console.ReadLine());

            mandaty = new int[groupCount];
            glosy = new int[groupCount];
            calcTab = new float[groupCount];

            Console.Write("Podaj liczbe mandatow: ");
            mandatesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < groupCount; i++)
            {
                Console.Write("Podaj liczbe glosow na partie " + (i + 1) + ": ");
                glosy[i] = int.Parse(Console.ReadLine());
            }
       
            for (int i = 0; i < groupCount; i++) mandaty[i] = 0;
            for (int i = 0; i < groupCount; i++) calcTab[i] = glosy[i];
         
            for (int i = 0; i < mandatesCount; i++)
            {
                max = -1;
                for (int j = 0; j < groupCount; j++)
                {
                    if (max < calcTab[j])
                    {
                        max = calcTab[j];
                        maxInd = j;
                    }
                }
                mandaty[maxInd]++;
                calcTab[maxInd] = (float)((glosy[maxInd] * 1.0) / (mandaty[maxInd] + 1.0));
            }

            for (int i = 0; i < groupCount; i++)
            {
                Console.WriteLine("Partia " + (i + 1) + ": " + mandaty[i]);
            }
            Console.ReadLine();
        }
        static void zad3()
        {
            int[] wartosc = { 10, 50, 70 };
            int[] waga = { 10, 20, 30 };
            int pojemnosc = 40;
            int ilosc = 3;

            int[,] plecak = new int[ilosc + 1, pojemnosc + 1];
            for (int i = 0; i <= ilosc; i++)
            {
                for (int j = 0; j <= pojemnosc; j++)
                {
                    if (i == 0 || j == 0)
                    {
                        plecak[i, j] = 0;
                    }
                    else if (waga[i - 1] <= j)
                    {
                        plecak[i, j] = Math.Max(wartosc[i - 1] + plecak[i - 1, j - waga[i - 1]], plecak[i - 1, j]);
                    }
                    else
                    {
                        plecak[i, j] = plecak[i - 1, j];
                    }
                }
            }
            Console.Write("Wynik: {0}", plecak[ilosc, pojemnosc]);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            zad1();
        }
    }
}