编写用于回文生成的C或C#程序 [英] Write a C or C# program for palindrome generation

查看:65
本文介绍了编写用于回文生成的C或C#程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要C或C#代码才能获得这样的输出

I need C or C# code to get output like this

ABCDEFEDCBA
ABCDDCBA
ABCCBA
ABBA
AA

推荐答案

如果您要张贴作业,至少要使其看起来像您自己尝试做某事!

我们不做您的作业:这是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试一下,或者学一下神奇的话:您想要炸薯条吗?"
If you are going to post your homework, at least try to make it look like you have attempted to do something yourself!

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, or learn the Magic Words: "Do you want fries with that?"


请不要要求提供代码来解决您的作业问题.如果您不能为这样一个简单的问题弄清楚逻辑,那么请返回您的讲义并努力学习.如果仍然无法解决问题,请去老师那里寻求额外的学费.
Please do not ask for code to solve your homework questions. If you cannot work out the logic for such a simple question then go back to your lecture notes and study hard. If you still cannot work it out then go to your teacher and ask for some extra tuition.


创建一个控制台应用程序,并将所有代码替换为替换代码.

Create a console application and replace all the codes with the blow lines.

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#程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆