示例#1
0
        /// <summary>
        /// 获得cf比赛的信息
        /// </summary>
        /// <param name="contestId">比赛url里面的id</param>
        /// <returns></returns>
        public CfContestInfo GetContestInfo(int contestId)
        {
            var info = new CfContestInfo();
            info.ContestId = contestId;
            info.type = "cf";

            string url = string.Format("http://codeforces.com/contest/{0}/standings/page/1", contestId);
            string web = Http.Get(url, null);

            info.ContestUrl=url;

            string regexPattern = "0.5em auto;\\\">(.*?)</div>";
            Regex reg = new Regex(regexPattern, RegexOptions.Compiled);
            var match = reg.Match(web);
            info.ContestName = match.Result("$1").Trim();

            regexPattern = @"Div\. (\d)";
            reg = new Regex(regexPattern, RegexOptions.Compiled);
            match = reg.Match(web);
            info.div = Convert.ToInt32(match.Result("$1"));

            return info;
        }
示例#2
0
        public void GetContestInfoTest()
        {
            CodeforcesProvider target = new CodeforcesProvider(); // TODO: 初始化为适当的值
            int contestId = 139; // TODO: 初始化为适当的值
            CfContestInfo expected = new CfContestInfo()
            {
                ContestUrl = "http://codeforces.com/contest/139/standings/page/1",
                ContestName = "Codeforces Beta Round #99 (Div. 2)",
                ContestId = 139,
                type = "cf",
                div=2
            };

            CfContestInfo actual;
            actual = target.GetContestInfo(contestId);
            Assert.AreEqual(expected.ContestId, actual.ContestId);
            Assert.AreEqual(expected.ContestName, actual.ContestName);
            Assert.AreEqual(expected.div, actual.div);
            Assert.AreEqual(expected.ContestUrl, actual.ContestUrl);
            Assert.AreEqual(expected.type, actual.type);
        }