读书人

其次周 任务七 判断S所指的字符串是否

发布时间: 2012-09-17 12:06:51 作者: rapoo

第二周 任务七 判断S所指的字符串是否回文

/* * 程序头部注释开始   * 程序的版权和版本声明部分   * Copyright (c) 2011, 烟台大学计算机学院学生   * All rights reserved.   * 文件名称:判断S所指的字符串是否回文                               * 作    者:薛广晨                               * 完成日期:2011  年 09 月  09  日   * 版 本号:x1.0               * 对任务及求解方法的描述部分   * 输入描述:  * 问题描述:判断S所指的字符串是否回文(即顺读和逆读相同的字符串)  * 程序输出:   * 程序头部的注释结束 */using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace PalindromicNumber{    class Program    {        static void Main(string[] args)        {            Console.Write("请输入您所要判断的字符串:");              string s = Console.ReadLine();              char[] c = s.ToCharArray();            int i;             int j = c.Length-1;              for(i = 0; i < j; i++, j--)            {                if (c[i] != c[j])                    break;            }                       if (i >= j)            {                Console.WriteLine("字符串{0}回文", s);            }            else            {                Console.Write("字符串{0}不回文", s);            }            Console.ReadKey();        }    }}


其次周  任务七 判断S所指的字符串是否回文

读书人网 >编程

热点推荐