bacco

Контролно число; return;

Feb 22nd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2.  
  3. namespace КоледнаШапка
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var n = int.Parse(Console.ReadLine());
  10.             var m = int.Parse(Console.ReadLine());
  11.             var controlNum = int.Parse(Console.ReadLine());
  12.  
  13.             var counter = 0;
  14.             var sum = 0;
  15.  
  16.             for (int first = 1; first <= n; first++)
  17.             {
  18.  
  19.                 for (int second = m; second >= 1; second--)
  20.                 {
  21.                     sum += first * 2 + second * 3;
  22.                     counter++;
  23.                    
  24.                     if (sum >= controlNum)
  25.                     {
  26.                         Console.WriteLine($"{counter} moves");  
  27.                         Console.WriteLine($"Score: {sum} >= {controlNum}");  
  28.                         return;
  29.                     }
  30.                    
  31.                 }
  32.                
  33.             }
  34.             Console.WriteLine($"{counter} moves");
  35.         }
  36.     }
  37. }
  38.  
  39. //                  Контролно число
  40.  
  41. //                  3
  42. //                  4
  43. //                  115
  44.  
  45. //                  10 moves
  46. //                  Score: 117 >= 115
Advertisement
Add Comment
Please, Sign In to add comment