日期:2014-05-17  浏览次数:21033 次

c# 判断输入字符串是否回文

回文:

例如 :
txt bccb等

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        
        static void Main(string[] args)
        {

            int nu1, nu2,k;
            string str;
            k = 0;
            str = Console.ReadLine();
            for (nu1 = 0, nu2 = str.Length - 1; nu1 <= nu2; nu1++, nu2--)
            {
                if (str[nu1] != str[nu2])
                    k = 1;
                break;
            }
            if (k==0)
                Console.WriteLine("yes");
            else
                Console.WriteLine("no");
            Console.ReadKey();
        }
    }
}