首页 > 其他 > 详细

练习题 求字符串是否为回文

时间:2017-07-12 09:30:08      阅读:296      评论:0      收藏:0      [点我收藏+]

原文发布时间为:2009-03-09 —— 来源于本人的百度文章 [由搬家工具导入]

using System;

namespace unname
{
   public class Program//是否回文
    {
       public static void Main(string[] args)
        {
           string str= Console.ReadLine();
           int i=0,j=str.Length-1;
           //注释部分为另一种解法
            //for (i = 0; i <= (str.Length - 1) >> 1; i++)
            //{
            //    if (str[i] != str[str.Length - 1 - i])
            //        break;
            //}
            //if (i > (str.Length - 1) >> 1)
            //    Console.WriteLine("是回文");
            //else
            //    Console.WriteLine("不是回文");

            while (i < j)
            {
                if (str[i] != str[j])
                    break;
                else
                {
                    i++;
                    j--;
                }
            }
           if(i<j)
               Console.WriteLine("不是回文");
           else
               Console.WriteLine("是回文");
            Console.ReadLine();
       }
   }
}

练习题 求字符串是否为回文

原文:http://www.cnblogs.com/handboy/p/7153285.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!