Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. static void Plecak(int[] przedmioty, int[] wartosciprzedmiotow, int pojemnosc)
  2.         {
  3.             Segreguj(wartosciprzedmiotow, przedmioty);
  4.             int suma = 0;
  5.             int[] ilosciprzedmiotow = new int[przedmioty.Length];
  6.             for (int i = 0; i < przedmioty.Length; i++)
  7.             {
  8.                 if (pojemnosc / wartosciprzedmiotow[i] <= 0)
  9.                 {
  10.                     continue;
  11.                 }
  12.                 if ((pojemnosc / wartosciprzedmiotow[i] <= przedmioty[i]) && (pojemnosc / wartosciprzedmiotow[i] > 0))
  13.                 {
  14.                     ilosciprzedmiotow[i] = pojemnosc / wartosciprzedmiotow[i];
  15.                     pojemnosc -= ilosciprzedmiotow[i] * wartosciprzedmiotow[i];
  16.                 }
  17.                 if (pojemnosc / wartosciprzedmiotow[i] > przedmioty[i] && (pojemnosc / wartosciprzedmiotow[i] > 0))
  18.                 {
  19.                     ilosciprzedmiotow[i] = przedmioty[i];
  20.                     pojemnosc -= ilosciprzedmiotow[i] * wartosciprzedmiotow[i];
  21.                 }
  22.  
  23.                 suma += ilosciprzedmiotow[i] * wartosciprzedmiotow[i];
  24.             }
  25.             for (int i = 0; i < ilosciprzedmiotow.Length; i++)
  26.             {
  27.                 Console.Write("ilosc przedmiotu nr" + i + " " + ilosciprzedmiotow[i] + " ");
  28.             }
  29.             Console.WriteLine();
  30.             Console.WriteLine("Suma wszystkich przedmiotow " + suma);
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement