Advertisement
grach

2017_19_March_E_Control Number

Jul 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 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 Control_Number
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {                      
  13.                 int N = int.Parse(Console.ReadLine());
  14.                 int M = int.Parse(Console.ReadLine());
  15.                 int ControlNumber = int.Parse(Console.ReadLine());
  16.  
  17.                 int counter = 0;
  18.                 int sum = 0;
  19.                 int endSum = 0;
  20.  
  21.                 for (int i = 1; i <= N; i++)
  22.                 {
  23.                     for (int j = M; j >= 1; j--)
  24.                     {
  25.                         sum = i * 2 + j * 3;
  26.                         endSum += sum;
  27.                         counter++;
  28.                         if (endSum >= ControlNumber)
  29.                         {
  30.                             break;
  31.                         }
  32.                     }
  33.                     if (endSum >= ControlNumber)
  34.                     {
  35.                         break;
  36.                     }
  37.                 }
  38.                 if (endSum >= ControlNumber)
  39.                 {
  40.                     Console.WriteLine("{0} moves", counter);
  41.                     Console.WriteLine("Score: {0} >= {1}", endSum, ControlNumber);
  42.                 }
  43.                 else
  44.                 {
  45.                     Console.WriteLine("{0} moves", counter);
  46.                 }
  47.             }
  48.         }
  49.     }
  50.  
  51.             /*
  52.             int n = int.Parse(Console.ReadLine());
  53.             int m = int.Parse(Console.ReadLine());
  54.             var controlNum = decimal.Parse(Console.ReadLine());
  55.  
  56.             var counter = 0;
  57.             var sum = 0;
  58.  
  59.  
  60.             for (int i = n; i <= m; i++)
  61.             {
  62.                 for (int j = n; j <= m; j++)
  63.                 {
  64.                     counter++;
  65.                     sum = (i + j);
  66.                     if (sum == controlNum)
  67.                     {
  68.                         Console.Write($"Combination N:{counter} ");
  69.                         Console.WriteLine($"({i} + {j} = {sum})");
  70.                         break;
  71.                     }
  72.                 }
  73.                 if (sum == controlNum)
  74.                     break;
  75.             }
  76.             if (sum != controlNum)
  77.                 Console.WriteLine($"{counter} combinations - neither equals {magicNumber}");
  78.         }
  79.     }
  80. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement