private void RunSolution(Problem problem, string assembly, ref Attempt attempt) { Verdict verdict = Verdict.Wrong_answer; foreach (var testCase in problem.TestCases) { Process process = new Process(); process.StartInfo.FileName = assembly; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.ErrorDialog = false; process.Start(); StreamWriter stdInputWriter = process.StandardInput; StreamReader stdOutputReader = process.StandardOutput; stdInputWriter.WriteLine(testCase.Input); string res = stdOutputReader.ReadToEnd(); if (string.Compare(res.Trim(), testCase.Output, StringComparison.InvariantCultureIgnoreCase) == 0) { verdict = Verdict.Accepted; } else { verdict = Verdict.Wrong_answer; break; } var result = new AttemptionResult(testCase.Input, testCase.Output, res); attempt.TestCases.Add(result); // process.Kill(); } if (verdict == Verdict.Accepted) { view.Print("Дұрыс жауап!\n", ConsoleColor.Green); } else { view.Print("Қате жауап!\n", ConsoleColor.Red); } ReadKey(); }
/// <summary> /// Берілген есептің бағдарламасын тесткейстерде тексереді. Тексеру нәтижесін attempt айнымалысына жазады /// </summary> /// <param name="problem">Есептің берілгені және тесттері</param> /// <param name="assembly">Есептің бағдарламасының аты</param> /// <param name="attempt">Осы айнымалыға есептің тесттерден көткендегі вердикттері жазылады</param> public void RunSolution(Problem problem, string assembly, ref Attempt attempt) { Verdict verdict = Verdict.Wrong_answer; foreach (var testCase in problem.TestCases) { Process process = new Process(); process.StartInfo.FileName = "dotnet"; process.StartInfo.Arguments = assembly; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.ErrorDialog = false; process.Start(); StreamWriter stdInputWriter = process.StandardInput; StreamReader stdOutputReader = process.StandardOutput; stdInputWriter.WriteLine(testCase.Input.Replace(' ', '\n')); string res = stdOutputReader.ReadToEnd(); if (string.Compare(res.Trim(), testCase.Output, StringComparison.InvariantCultureIgnoreCase) == 0) { verdict = Verdict.Accepted; } else { verdict = Verdict.Wrong_answer; break; } var result = new AttemptionResult(testCase.Input, testCase.Output, res); attempt.TestCases.Add(result); } // Вердикт өзгертілгендіктен, OnStatusChanged оқиғасы шақырылады if (verdict == Verdict.Accepted) { OnStatusChanged(new ConsoleRewriteEventArgs("Accepted".PadLeft(20), 3, 49, Console.CursorLeft, Console.CursorTop, ConsoleColor.Green)); } else { OnStatusChanged(new ConsoleRewriteEventArgs("Wrong_answer".PadLeft(20), 3, 49, Console.CursorLeft, Console.CursorTop, ConsoleColor.Red)); } attempt.Verdict = verdict; }
private void RunSolution(Problem problem, string assembly, ref Attempt attempt) { Verdict verdict = Verdict.Wrong_answer; foreach (var testCase in problem.TestCases) { Process process = new Process(); process.StartInfo.FileName = "dotnet"; process.StartInfo.Arguments = assembly; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.ErrorDialog = false; process.Start(); StreamWriter stdInputWriter = process.StandardInput; StreamReader stdOutputReader = process.StandardOutput; stdInputWriter.WriteLine(testCase.Input.Replace(' ', '\n')); string res = stdOutputReader.ReadToEnd(); if (string.Compare(res.Trim(), testCase.Output, StringComparison.InvariantCultureIgnoreCase) == 0) { verdict = Verdict.Accepted; } else { verdict = Verdict.Wrong_answer; break; } var result = new AttemptionResult(testCase.Input, testCase.Output, res); attempt.TestCases.Add(result); // process.Kill(); } //Негізгі есептеулер if (attempt.User is Student student) // студент жағдайын ғана қарастыру { attempt.Verdict = verdict; int acceptedCnt = attempt.User.Attempts.Where(a => a.Problem == problem) .Count(a => a.Verdict == Verdict.Accepted); // Текущий есептің дұрыс жауаптар саны int cnt = attempt.User.Attempts.Where(a => a.Problem == problem).ToList().Count - acceptedCnt; // штраф анықтау үшін текущий есептің барлық попыткасынан дұрыс жауап санын алып тастау керек. if (verdict == Verdict.Accepted && acceptedCnt == 1 ) // тек бірінші дұрыс қана қабылданады. екінші рет қайта жібергенде, ұпай қосылмайды. { student.CurrentPoint += (problem.Point - (cnt * 50) >= 150 ? problem.Point - (cnt * 50) : 150 ); // штраф ұпайын алып тастап currentPoint - қа қосады. Егер өте көп попытка жіберіп, алған ұпайы минимальды көрсеткіштен төмен болса, оғпн минимум ұпай беріледі. } double percent = 0; if (model.Problems != null) { percent = student.CurrentPoint * 1.0 / model.Problems.Sum(s => s.Point) * 100; // үлгерімін есептеу } student.Gpa = percent; } if (verdict == Verdict.Accepted) { view.Print("Дұрыс жауап!\n", ConsoleColor.Green); } else { view.Print("Қате жауап!\n", ConsoleColor.Red); } ReadKey(); }