判断一个字符串是否为回文。回文是指一个字符序列以中间字符为基准两边字符完全相同的字符序列,如:ABCFCBA
程序中我引用了已经封装好的文件QueueStack.dll,这个文件其实就是前面2个队列和栈类封装在一个类库中的。具体如何实现类的封装,网上有很多例子,这里不写出来了。
代码见下:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using QueueStack;
5
namespace 队列应用
6
{
7
class Program
8
{
9
10
static void Main(string[] args)
11
{
12![]()
13
QueueStack.stack.SeqStack<char> sta = new QueueStack.stack.SeqStack<char>(10);
14
QueueStack.queue.SeqQueue<char> que = new QueueStack.queue.SeqQueue<char>(10);
15
string str = Console.ReadLine();
16
for (int i = 0; i < str.Length; i++)
17
{
18
sta.Push(str[i]);
19
que.In(str[i]);
20
}
21
while (!sta.IsEmpty() && !que.IsEmpty())
22
{
23
if (sta.Pop() != que.Out())
24
{
25
break;
26
}
27
}
28
if (!sta.IsEmpty() || !que.IsEmpty())
29
{
30
Console.WriteLine("这不是回文哦!");
31
}
32
else
33
{
34
Console.WriteLine("这是回文哦!");
35
}
36
}
37
}
38
}
39![]()
using System;2
using System.Collections.Generic;3
using System.Text;4
using QueueStack;5
namespace 队列应用6
{7
class Program8
{9
10
static void Main(string[] args)11
{12

13
QueueStack.stack.SeqStack<char> sta = new QueueStack.stack.SeqStack<char>(10);14
QueueStack.queue.SeqQueue<char> que = new QueueStack.queue.SeqQueue<char>(10);15
string str = Console.ReadLine();16
for (int i = 0; i < str.Length; i++)17
{18
sta.Push(str[i]);19
que.In(str[i]);20
}21
while (!sta.IsEmpty() && !que.IsEmpty())22
{23
if (sta.Pop() != que.Out())24
{25
break;26
}27
}28
if (!sta.IsEmpty() || !que.IsEmpty())29
{30
Console.WriteLine("这不是回文哦!");31
}32
else33
{34
Console.WriteLine("这是回文哦!");35
}36
}37
}38
}39



浙公网安备 33010602011771号