Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int weight = 0 ;
- Console.WriteLine("Input Weight :");
- weight = int.Parse(Console.ReadLine());
- Console.WriteLine(BACKPACK(weight));
- }
- public static string BACKPACK(int n)
- {
- string[] i = { "flatscreen monitor", "processor", "motherboard", "HD","UPS","printer", "scanner","memory", "stand","system case","wireless router","headset","speaker","camera","LAN Card","Mouse","Chair","Keyboard"};
- int[] v = {15900,14250,12950,9450,5600,4700,4500,3800,2500,2400,1900,1300,1300,1050,980,750,500,250};
- int [] w = { 550,200,1000,750,1500,1000,1250,150,10000,1000,400,400,550,300,500,350,5000,400};
- string Items = "";
- //double Sum = 0;
- int totalvalue = 0 ;
- int totalweight = 0;
- int index = 0;
- while (totalweight <= n)
- {
- if (totalweight + w[index] <= n)
- {
- Items = Items + i[index]+ "____" + w[index]+ "____" + v[index]+ "\n";
- totalweight = totalweight + w[index];
- totalvalue = totalvalue + v[index];
- }
- index++;
- if (index == w.Length)
- break;
- }
- return Items + "\ntotal weight :"+totalweight.ToString()+"\ntotal value :" +totalvalue.ToString();
- //while (Sum != n)
- //{
- // for (int index = 0; index <= w.Length - 1; )
- // {
- // if (Sum + w[index] <= n)
- // {
- // int y = w[index];
- // Items = Items + y;
- // Sum = Sum + y;
- // }
- // else
- // index++;
- // }
- //}
- //return Items;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement