本文介绍了编写用于回文生成的C或C#程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要C或C#代码才能获得这样的输出
I need C or C# code to get output like this
ABCDEFEDCBA
ABCDDCBA
ABCCBA
ABBA
AA
推荐答案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sample
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.PrintMethod();
}
public void PrintMethod()
{
int length;
string[] chars = new string[] {"A","B","C","D","E","F" };
length = chars.Length - 1;
while (chars[0] != string.Empty)
{
foreach (string str in chars)
{
if (str == string.Empty)
{
Console.Write(" ");
}
else
{
Console.Write(str);
}
}
for (int i = chars.Length - 2; i >= 0; i--)
{
if (chars[i] == string.Empty)
{
Console.Write(" ");
}
else
{
Console.Write(chars[i]);
}
}
chars[length] = string.Empty;
Console.Write(Environment.NewLine);
length--;
}
Console.ReadLine();
}
}
}
这篇关于编写用于回文生成的C或C#程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!