Beispiel #1
0
        public static List <Problem> ReadProblemsAll(Contest contest)
        {
            List <Problem> problems = new List <Problem>();
            string         page     = string.Empty;

            using (WebClient wc = new WebClient())
            {
                wc.Init();
                Console.WriteLine(contest.Url + "/problems");
                page = wc.DownloadString(contest.Url + "/problems");
            }
            List <string> titles  = page.ParseHtml(@"<div class=""title"">", @"</div>");
            List <string> inputs  = page.ParseHtml(@"<div class=""title"">Input</div><pre>", "</pre>");
            List <string> outputs = page.ParseHtml(@"<div class=""title"">Output</div><pre>", "</pre>");

            for (int i = 0, j = 0; i < titles.Count && j < inputs.Count;)
            {
                Problem problem = new Problem();
                problem.Name = titles[i].Trim();
                while (++i < titles.Count && (titles[i] == "Input" || titles[i] == "Output"))
                {
                    if (titles[i] == "Input")
                    {
                        TestCase tc = new TestCase();
                        tc.Input  = "\\\r\n" + inputs[j].Replace(@"<br />", "\\n\\\r\n");
                        tc.Output = "\\\r\n" + outputs[j].Replace(@"<br />", "\\n\\\r\n");
                        problem.TestCases.Add(tc);

                        ++j;
                    }
                }
                problems.Add(problem);
            }

            return(problems);
        }
Beispiel #2
0
        public ProblemCdt(Problem problem, Contest contest)
        {
            p = problem;
            c = contest;

            GenerateCommand = new IDelegateCommand((obj) =>
            {
                //var app = Connect.applicationObject;
                var ps = ProblemsViewModel.Instance;
                //var proj = app.GetActiveProject();
                //if (proj == null)
                //{
                //    string msg = "first open a project please !";
                //    if (ps.Status.Contains(msg))
                //        ps.Status = ps.Status + "!";
                //    else
                //        ps.Status = msg;
                //    return;
                //}
                string folder = Database.Instance.WorkingDirectory;
                folder        = System.IO.Path.Combine(folder, c.Name.SafePath());
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                //foreach (ProjectItem pi in proj.ProjectItems)
                //    if (pi.Name == p.Name.SafePath())
                //        pi.Remove();


                string cpp = System.IO.Path.Combine(folder, p.Name.SafePath() + extension);
                if (!File.Exists(cpp) || MessageBox.Show("Overwrite File?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    StreamWriter sw = new StreamWriter(cpp, false);
                    WriteTemplate(sw);
                    sw.Close();
                }

                //proj.ProjectItems.AddFromFile(cpp).Open();
            });

            ShowInBrowser = new IDelegateCommand((obj) =>
            {
                bool exception_accured = false;
                string browser         = string.Empty;
                try
                {
                    browser = "chrome";
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("chrome.exe", c.Url + "/problem/" + p.Name.First()));
                }
                catch (Exception e)
                {
                    ProblemsViewModel.Instance.Status = e.Message;
                    try
                    {
                        browser = "ie";
                        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("explorer.exe", c.Url + "/problem/" + p.Name.First()));
                    }
                    catch (Exception e2)
                    {
                        ProblemsViewModel.Instance.Status = e2.Message;
                        exception_accured = true;
                    }
                }
                if (!exception_accured)
                {
                    ProblemsViewModel.Instance.Status = p.Name + " launched in " + browser + " .";
                }
            });


            TestCommand = new IDelegateCommand((obj) =>
            {
                try
                {
                    string folder = Database.Instance.WorkingDirectory;
                    folder        = System.IO.Path.Combine(folder, c.Name.SafePath());
                    string exe    = System.IO.Path.Combine(folder, p.Name.SafePath() + ".exe");
                    string cpp    = System.IO.Path.Combine(folder, p.Name.SafePath() + extension);

                    bool run = true;
                    {
                        string cmdarg = $"/C g++.exe -Wl,--stack=268435456 -O2 -std=c++17 -o \"{exe}\" \"{cpp}\"";
                        var psi       = new System.Diagnostics.ProcessStartInfo("cmd", cmdarg);
                        psi.RedirectStandardOutput = true;
                        psi.RedirectStandardError  = true;
                        psi.UseShellExecute        = false;
                        var proc = System.Diagnostics.Process.Start(psi);
                        proc.WaitForExit();
                        var compilelog  = proc.StandardOutput.ReadToEnd().Replace(folder, ""); // remove useless information
                        var compilelog2 = proc.StandardError.ReadToEnd().Replace(folder, "");
                        if (compilelog != string.Empty || compilelog2 != string.Empty)
                        {
                            run = MessageBox.Show(compilelog + "\r\n" + compilelog2 + "\r\n Would you like to try and run anyway?", "Compile Log", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.No;
                        }
                    }
                    if (run)
                    {
                        var psi = new System.Diagnostics.ProcessStartInfo("cmd", $"/C \"{exe}\" & pause");
                        psi.WorkingDirectory = folder;
                        System.Diagnostics.Process.Start(psi);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Exception");
                }
            });
        }