Advertisement
Guest User

Untitled

a guest
Mar 4th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication29
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int foundInARow = 0;
  13.             int maxThatCannotBePurchased = 0;
  14.  
  15.             for (int i = 0; i < 50; i++)
  16.            
  17.             {
  18.                 bool canPurchaseThisAmount = false;
  19.  
  20.                 for (int a = 0; a < i / 6 + 1; a++)
  21.                 {
  22.                     for (int b = 0; b < i / 9 + 1; b++)
  23.                     {
  24.                         for (int c = 0; c < i / 20 + 1; c++)
  25.                         {
  26.                             int solution = (6*a) + (9*b) + (20*c);
  27.                             if (solution == i)
  28.                                 canPurchaseThisAmount = true;
  29.                         }
  30.                     }
  31.                 }
  32.  
  33.                 if (canPurchaseThisAmount)
  34.                 {
  35.                     foundInARow += 1;
  36.                     if (foundInARow == 6)
  37.                         break;
  38.                 }
  39.                 else
  40.                 {
  41.                     foundInARow = 0;
  42.                     maxThatCannotBePurchased = i;
  43.                 }
  44.             }
  45.             Console.WriteLine("Largest number of McNuggets that cannot be bought in exact quantity:"+maxThatCannotBePurchased);
  46.             Console.ReadLine();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement