zoukankan      html  css  js  c++  java
  • 练习题 求字符串是否为回文

    原文发布时间为: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();
           }
       }
    }

  • 相关阅读:
    HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)
    HDU 3938:Portal(并查集+离线处理)
    HDU 1811:Rank of Tetris(并查集+拓扑排序)
    HDU 1074:Doing Homework(状压DP)
    HDU 1024:Max Sum Plus Plus(DP)
    最最最亲爱哒
    hlg-1332 买电脑 ---二分
    时间过得很快
    0514
    hlg1551Assemble--暴力求解
  • 原文地址:https://www.cnblogs.com/handboy/p/7153285.html
Copyright © 2011-2022 走看看