有人可以描述该程序的作用吗? [英] Can someone describe the program as to what it does?

查看:56
本文介绍了有人可以描述该程序的作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _08137_ACW2_Code
{
    class Program
    {
        static void Main(string[] args)
        {
            string x;
            bool f;
            int a, z, g; 
            x = Console.ReadLine();
            g = x.Length;
            z = (g - 1);
            a = 0;

            if (g == 1)
            {
                f = true;
            }
            else
            {
                f = true;

                while (f == true && a < z)
                {
                    while (x[a] == ' ' || x[a] == ',' || x[a] == ';' || x[a] == '!' || x[a] == '?' || x[a] == '.')
                    {
                        a++; 
                    }

                    while (x[z] == ' ' || x[z] == ',' || x[z] == ';' || x[z] == '!' || x[z] == '?' || x[z] == '.')
                    {
                        z--; 
                    }

                    if (x[a].ToString().ToUpper() == x[z].ToString().ToUpper()) 
                    {
                        a++; 
                        z--;                     }
                    else
                    {
                        f = false;
                    }
                }
            }

            if (f == false)
            {
                Console.WriteLine("The string you entered is NOT a palindrome.");
            }
            else
            {
                Console.WriteLine("The string you entered IS a palindrome.");
            }
        }
    }
}





我尝试了什么:



我试过读代码,但我无法理解



What I have tried:

I have tried the reading the code, but I can't understand it

推荐答案

没有。

它编写得很糟糕,没有文档记录,收缩严重,充满无意义的代码,容易出现故障。

当你在循环外进行循环保护检查时这会改变价值观,这总是一个不好的迹象......:笑:



但作为一个猜测,它通过(严重)忽略非字母来检查回文字符和两端比较。但它会报告TACO-CAT不是回文,当它是...



将代码交回给你的伴侣,告诉他可能会当他交出来时会得到一个失败的标记,然后自己编写一个失败的标记!
No.
It's poorly written, undocumented, badly indented, full of pointless code, and prone to failure.
When you have your loop guard checks outside the loop that changes the values, that's always a bad sign... :laugh:

But as a guess, it checka for a palindrome by (badly) ignoring non-letter characters and comparing from both ends. But it would report that "TACO-CAT" is not a palindrome, when it is...

Give the code back to your mate, tell him it will probably get a fail mark when he hands it in, and write your own properly!


如果你被给了一些代码并且你不知道它做了什么我必须假设这是一个任务或家庭作业。



我们不会为你做功课。它将帮助学习并巩固你的大脑中的知识



鉴于此处的消息代码的结尾我会说它正在测试一些输入以确定该输入是否是回文。我怀疑只是说这对你的老师来说已经足够了。



我能给你的最好建议是在调试模式下运行程序(参见在Visual Studio 2010中进行调试 - 初学者指南 [ ^ ])并尝试按照它正在做的事情
If you have been given some code and you have no idea what it does I must assume that is an assignment or homework.

We do not do your homework for you. It is set to help you learn and to cement that knowledge in your brain

Given the messages at the end of the code I would say that it is testing some input to determine whether or not that input is a palindrome. I doubt just saying that will be sufficient for your teacher though.

The best advice I can give you is to run the program in debug mode (see Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^] ) and attempt to follow what it is doing


这篇关于有人可以描述该程序的作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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