Advertisement
Guest User

Problem 06 - Control Number

a guest
Mar 22nd, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06ControlNums
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int firstNum = int.Parse(Console.ReadLine());
  14.             int secondNum = int.Parse(Console.ReadLine());
  15.             int controlNum = int.Parse(Console.ReadLine());
  16.             int numCombinations = 0;
  17.             int sumOfNumbers = 0;
  18.             bool checkControlNum = false;
  19.             for (int combination1 = 1; combination1 <= firstNum; combination1++)
  20.             {
  21.                 for (int combination2 = secondNum; combination2 >= 1; combination2--)
  22.                 {
  23.                     numCombinations++;
  24.                     sumOfNumbers += combination1 * 2 + combination2  * 3;
  25.                     if(sumOfNumbers >= controlNum )
  26.                     {
  27.                         checkControlNum = true;
  28.                         break;
  29.                     }
  30.                 }
  31.                 if (checkControlNum) break;
  32.             }
  33.  
  34.             Console.WriteLine("{0} moves",numCombinations );
  35.  
  36.             if (checkControlNum)
  37.             {
  38.                 Console.WriteLine("Score: {0} >= {1}",sumOfNumbers,controlNum );
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement