Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Zad4
- {
- class Program
- {
- static List<int> plecak(List<int> przedmioty, int pojemnosc)
- {
- List<int> ile = new List<int>();
- int bufor = 0;
- while (pojemnosc>=przedmioty.Max())
- {
- ile.Add(przedmioty.Max());
- bufor = przedmioty.Max();
- pojemnosc -= bufor;
- przedmioty.Remove(przedmioty.Max());
- }
- return ile;
- }
- static void Main(string[] args)
- {
- Random r = new Random();
- List<int> przedmioty = new List<int>(25);
- for (int i = 0; i < 25; i++)
- {
- przedmioty.Add(r.Next(0,100));
- }
- foreach (var i in przedmioty)
- {
- Console.Write(i + ",");
- }
- Console.WriteLine();
- int pojemnosc = 1000;
- List<int> wynik = plecak(przedmioty, pojemnosc);
- int ilosc = 0;
- foreach (var i in wynik)
- {
- Console.Write(i + ",");
- ilosc += i;
- }
- Console.WriteLine("Łączna waga wynosi: " + ilosc);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement