using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); int i = 0; for (; a + c > b && b + c > a && b + a > c; i++) { a -= 1; b -= 1; c -= 1; } Console.WriteLine(i); } } } C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { internal class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); int i = 0; for (; a + c > b && b + c > a && b + a > c; i++) { a -= 1; b -= 1; c -= 1; } Console.WriteLine(i); } } }
Так оно и выполняется меньше секунды, если не учитывать ввод цифр Вот код с эмуляцией ввода цифр и нажатия на Enter using System; using System.Diagnostics; using System.Windows.Forms; namespace ConsoleApp1 { class Program { public static Stopwatch stopwatch = new Stopwatch(); static void Main() { stopwatch.Start(); SendKeys.SendWait("55"); SendKeys.SendWait("{Enter}"); int a = int.Parse(Console.ReadLine()); SendKeys.SendWait("25"); SendKeys.SendWait("{Enter}"); int b = int.Parse(Console.ReadLine()); SendKeys.SendWait("74"); SendKeys.SendWait("{Enter}"); int c = int.Parse(Console.ReadLine()); int i = 0; for (; a + c > b && b + c > a && b + a > c; i++) { a -= 1; b -= 1; c -= 1; } Console.WriteLine(i); // Code End stopwatch.Stop(); Console.WriteLine("Время: " + stopwatch.Elapsed.Days + ":" + stopwatch.Elapsed.Hours + ":" + stopwatch.Elapsed.Minutes + ":" + stopwatch.Elapsed.Seconds + ":" + stopwatch.Elapsed.Milliseconds); Console.WriteLine("Секунд: " + stopwatch.Elapsed.TotalSeconds); // End Program Console.WriteLine("Нажмите Enter, для закрытия программы"); Console.ReadLine(); } } } C# using System; using System.Diagnostics; using System.Windows.Forms; namespace ConsoleApp1 { class Program { public static Stopwatch stopwatch = new Stopwatch(); static void Main() { stopwatch.Start(); SendKeys.SendWait("55"); SendKeys.SendWait("{Enter}"); int a = int.Parse(Console.ReadLine()); SendKeys.SendWait("25"); SendKeys.SendWait("{Enter}"); int b = int.Parse(Console.ReadLine()); SendKeys.SendWait("74"); SendKeys.SendWait("{Enter}"); int c = int.Parse(Console.ReadLine()); int i = 0; for (; a + c > b && b + c > a && b + a > c; i++) { a -= 1; b -= 1; c -= 1; } Console.WriteLine(i); // Code End stopwatch.Stop(); Console.WriteLine("Время: " + stopwatch.Elapsed.Days + ":" + stopwatch.Elapsed.Hours + ":" + stopwatch.Elapsed.Minutes + ":" + stopwatch.Elapsed.Seconds + ":" + stopwatch.Elapsed.Milliseconds); Console.WriteLine("Секунд: " + stopwatch.Elapsed.TotalSeconds); // End Program Console.WriteLine("Нажмите Enter, для закрытия программы"); Console.ReadLine(); } } }
xmka, нахера тебе эмуляция ввода цифр? просто запускай секндомер после того как введёшь данные а не перед тем как введёшь.
Во-первых, писать правильно стилистически. А i вообще можешь убрать, чуть побыстрее будет. В приципе цикл на while заменить можно. --- Сообщение объединено с предыдущим 28 окт 2022 while (a + c > b && b + c > a && b + a > c)
вообще по идее у тебя сложность получается O(n^3). почитай про анализ сложности алгоритмов и будет тебе счастье.