Advertisement
jhei13

KnafSucks PROBLEM001

Jul 21st, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1.  static void Main(string[] args)
  2.         {
  3.             int weight = 0 ;
  4.             Console.WriteLine("Input Weight :");
  5.             weight = int.Parse(Console.ReadLine());
  6.  
  7.             Console.WriteLine(BACKPACK(weight));
  8.         }
  9.         public static string BACKPACK(int n)
  10.         {
  11.             string[] i = { "flatscreen monitor", "processor", "motherboard", "HD","UPS","printer", "scanner","memory", "stand","system case","wireless router","headset","speaker","camera","LAN Card","Mouse","Chair","Keyboard"};
  12.             int[] v =     {15900,14250,12950,9450,5600,4700,4500,3800,2500,2400,1900,1300,1300,1050,980,750,500,250};
  13.             int [] w =       { 550,200,1000,750,1500,1000,1250,150,10000,1000,400,400,550,300,500,350,5000,400};
  14.             string Items = "";
  15.             //double Sum = 0;
  16.             int totalvalue = 0 ;
  17.             int totalweight = 0;
  18.             int index = 0;
  19.  
  20.  
  21.  
  22.             while (totalweight <= n)
  23.             {
  24.                 if (totalweight + w[index] <= n)
  25.                 {
  26.                     Items = Items + i[index]+ "____" + w[index]+ "____" + v[index]+ "\n";
  27.                     totalweight = totalweight + w[index];
  28.                     totalvalue = totalvalue + v[index];
  29.                 }
  30.                 index++;
  31.  
  32.                 if (index == w.Length)
  33.                     break;
  34.             }
  35.  
  36.             return Items + "\ntotal weight :"+totalweight.ToString()+"\ntotal value :" +totalvalue.ToString();
  37.             //while (Sum != n)
  38.             //{
  39.             //    for (int index = 0; index <= w.Length - 1; )
  40.             //    {
  41.             //        if (Sum + w[index] <= n)
  42.             //        {
  43.             //            int y = w[index];
  44.             //            Items = Items + y;
  45.             //            Sum = Sum + y;
  46.             //        }
  47.             //        else
  48.             //            index++;
  49.             //    }
  50.             //}
  51.  
  52.             //return Items;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement