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();
           }
       }
    }

  • 相关阅读:
    ok~加油!
    解析window.open链接的参数
    Arrya数组添加过滤条件
    Oracle 查询今天、昨日、本周、本月和本季度的所有记录
    Sql Server日期查询-SQL查询今天、昨天、7天内、30天
    Lua 中 pairs 和 ipairs 的区别
    关于SignalR连接数量问题的记录
    IceStorm示例运行步骤
    从 OPC 到 OPC UA
    SQL Server 2008 R2 Express Profiler
  • 原文地址:https://www.cnblogs.com/handboy/p/7153285.html
Copyright © 2011-2022 走看看