Advertisement
jhei13

knafsucksWITHkwanTT_exe006_ALGO[NEW]

Jul 25th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.            
  6.             string[] i = { "flatscreen monitor", "processor", "motherboard", "HD", "UPS", "printer", "scanner", "memory", "stand", "system case", "wireless router", "headset", "speaker", "camera", "LAN Card", "Mouse", "Chair", "Keyboard" };
  7.             int[] v = { 15900, 14250, 12950, 9450, 5600, 4700, 4500, 3800, 2500, 2400, 1900, 1300, 1300, 1050, 980, 750, 500, 250 };
  8.             int[] w = { 550, 200, 1000, 750, 1500, 1000, 1250, 150, 10000, 1000, 400, 400, 550, 300, 500, 350, 5000, 400 };
  9.             int[] I  = {2,3,5,4,5,1,3,2,2,1,1,3,5,5,5,1,3,1 };
  10.             int weight, sum = 0;
  11.             string Items = "";
  12.             int index = 0, totalweight = 0, totalvalue = 0;
  13.  
  14.             Console.Write("Input Weight: ");
  15.             weight = int.Parse(Console.ReadLine());
  16.  
  17.  
  18.             while (sum <= weight && index < w.Length)
  19.             {
  20.                 if (sum + w[index] <= weight)
  21.                 {
  22.                     totalweight = totalweight + w[index];
  23.                     totalvalue = totalvalue + v[index];
  24.                     sum = sum + w[index];
  25.                     Items = Items + i[index] + " sucks in the bag with " + w[index] + " grams " + " and " + v[index] + " Pesos \n";
  26.                     I[index] = I[index] - 1;
  27.                 }
  28.  
  29.  
  30.                 if (I[index] == 0 || w[index] > (weight - sum))
  31.                 {
  32.                     index++;
  33.                 }
  34.         }
  35.        
  36.              Console.WriteLine( Items + "\ntotal weight :"+totalweight.ToString()+"\ntotal value :" +totalvalue.ToString());
  37.              Console.ReadKey();
  38.            
  39.         }
  40.         //CODED BY JGT @ ASIAN COLLEGE OF TECHNOLOGY
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement