首页 > 学院 > 开发设计 > 正文

小算法:递归实现回文判断

2019-11-17 02:48:51
字体:
来源:转载
供稿:网友

小算法:递归实现回文判断

static void Main(string[] args)        {            DateTime dt1 = DateTime.Now;            string text = "abcdedcba";            bool bYes = Recv(text);            Console.Write("{0}:{1}回文!", text, bYes ? "是" : "不是");            DateTime dt2 = DateTime.Now;            Console.Write("耗时:{0}毫秒", (dt2 - dt1).TotalMilliseconds.ToString());            Console.ReadLine();        }        PRivate static bool Recv(string text)        {            string head = text.Substring(0, 1);            string end = text.Substring(text.Length - 1, 1);            if (head == end)            {                if (text.Length == 1)                    return true;                string t = text.Substring(1, text.Length - 2);                return Recv(t);            }            return false;        }

  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表