Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Plecak(int[] przedmioty, int[] wartosciprzedmiotow, int pojemnosc)
- {
- Segreguj(wartosciprzedmiotow, przedmioty);
- int suma = 0;
- int[] ilosciprzedmiotow = new int[przedmioty.Length];
- for (int i = 0; i < przedmioty.Length; i++)
- {
- if (pojemnosc / wartosciprzedmiotow[i] <= 0)
- {
- continue;
- }
- if ((pojemnosc / wartosciprzedmiotow[i] <= przedmioty[i]) && (pojemnosc / wartosciprzedmiotow[i] > 0))
- {
- ilosciprzedmiotow[i] = pojemnosc / wartosciprzedmiotow[i];
- pojemnosc -= ilosciprzedmiotow[i] * wartosciprzedmiotow[i];
- }
- if (pojemnosc / wartosciprzedmiotow[i] > przedmioty[i] && (pojemnosc / wartosciprzedmiotow[i] > 0))
- {
- ilosciprzedmiotow[i] = przedmioty[i];
- pojemnosc -= ilosciprzedmiotow[i] * wartosciprzedmiotow[i];
- }
- suma += ilosciprzedmiotow[i] * wartosciprzedmiotow[i];
- }
- for (int i = 0; i < ilosciprzedmiotow.Length; i++)
- {
- Console.Write("ilosc przedmiotu nr" + i + " " + ilosciprzedmiotow[i] + " ");
- }
- Console.WriteLine();
- Console.WriteLine("Suma wszystkich przedmiotow " + suma);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement