//所谓回文是指向前和向后拼写都完全一样的字符。例如,“dad”、“madam”都是回文。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace vc_test
{
class Program
{
private ArrayList list;
private int p_index;
public Program()
{
list = new ArrayList();
p_index = -1;
}
static void Main(string[] args)
{
Program myprograme = new Program();
string ch;
string word = " 1221 ";
bool ispalindrome = true;
for (int x = 0; x < word.Length; x++)
//添加到动态数组中
myprograme.push(word.Substring(x, 1));
int pos=0;
while (myprograme.list.Count > 0)
{
ch = myprograme.pop().ToString();
if (ch != word.Substring(pos, 1))
{
ispalindrome = false;
break;
}
pos++;
}
if (ispalindrome)
Console.WriteLine(word + " is a paliddrome");
else
Console.WriteLine(word+" is not a palindrome.");
Console.ReadKey();
}
//params可以指定不确定的参数数量
static int sumNums(params int[] nums)
{
int sum = 0;
for (int j = 0; j <= nums.GetUpperBound(0); j++)
{
//Console.Write("{0},",nums [i]);
sum+=nums[j];
}
return sum;
}
//插入
void push(object item)
{
list.Add(item );
p_index++;
}
//移除
public object pop()
{
object obj=list[p_index];
list.RemoveAt(p_index);
p_index--;
return obj;
}
}
}