曼哈顿距离C# [英] Manhattan Distance C#

查看:363
本文介绍了曼哈顿距离C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以将此程序转换为C#吗?因为我很难转换它.拜托?
谢谢你的帮忙.

Can someone convert this program to C#? because I''m having a hard time converting it. Please?
Thank you for helping.

#include <iostream>
using namespace std;
void show(int x1, int y1, int n);
int main()
{
    int x1, y1, n;
    cout << "Enter x coordinate of a point: ";
    cin >> x1;
    cout << "Enter y coordinate of a point: ";
    cin >> y1;
    cout << "Enter Manhattan Distance: ";
    cin >> n;
    show(x1, y1, n);
    cin.clear();
    cin.ignore(255, '\n');
    cin.get();
    return 0;
}
void show(int x1, int y1, int n)
{
    cout << "Points having distance 1 to " << n << " from ("<< x1 << ", " << y1 << ") are: "<< endl;
    for(int i = 1; i <= n; i++)
    {
        cout << "(" << x1 << ", " << (y1 + i) << ")" << endl;
        cout << "(" << x1 << ", " << (y1 - i) << ")" << endl;
        cout << "(" << (x1 + i) << ", " << y1 << ")" << endl;
        cout << "(" << (x1 - i) << ", " << y1 << ")" << endl;
        for(int j = 1; j <= i - 1; j++)
        {
            cout << "(" << (x1 + j) << ", " << (y1 + i - j) << ")" << endl;
            cout << "(" << (x1 - j) << ", " << (y1 + i - j) << ")" << endl;
            cout << "(" << (x1 + j) << ", " << (y1 - i + j) << ")" << endl;
            cout << "(" << (x1 - j) << ", " << (y1 - i + j) << ")" << endl;
        }
    }
}

推荐答案

我们不会为您做作业,但这是一个非常简单的转换,唯一隐约复杂的部分是输出. C#没有cout或流运算符<<".相反,您可以将其转换为:
We are not going to do your homework for you, but this is a very simple conversion, the only vaguely complicated part is the output. C# does not have cout, or an stream operator "<<". Instead, you convert this:
cout << "Points having distance 1 to " << n << " from ("<< x1 << ", " << y1 << ") are: "<< endl;

为此:

Console.WriteLine("Points having distance 1 to {0} from ({1}, {2}) are: ", n, x1, y1);


如果不确定该怎么做,请阅读字符串.格式 [^ ]涵盖了语法.

其余的都非常简单.


If you aren''t sure exactly what to do from that, then read up on String.Format[^] which covers the syntax.

The rest of it is pretty simple.


让我们看看.您已经在C#中的Manhattan Distance上完成了一些作业.您在网上搜索,一些愚蠢的schmuck发布了他们对作业的答案,但是它是用C ++编写的.您想要在C#中完全一样的东西,而不必费心进行转换.

抱歉,将其他人的答案转换为C#,这样您就可以上交,因为您自己的工作并不伴随我们.问题不在于您不知道如何将C ++代码转换为C#,而是您不能从头开始编写C#代码.没有复制"粘贴的答案.

我讨厌这样说,但你会不及格.为什么?因为在期末考试中,当您被要求编写代码,而您为答案而写的完全破损的代码与您作为家庭作业上交的答案的质量不符时,您将被发现你真的是...作弊.
Let''s see. You''ve got a homework assignment for something on Manhattan Distance in C#. You scoured the web and some stupid schmuck posted their answer to the assignment, but it''s in C++. You want the exact same thing in C# and can''t be bothered to do the conversion.

Sorry, but converting someone else''s answer into C# so you can turn it in as your own work doesn''t fly with us. The problem isn''t that you don''t know how to convert the C++ code to C#, but it''s that you can''t write C# code from scratch. There is no "copy''n''paste" answer for that.

I hate to say this but you''re going to fail your class. Why? Because on the final exam when you''re asked to write code and the completely broken code you write for answer doesn''t match the quality of the answers you''ve been turning in as homework you''ll be discovered for what you really are... a cheat.


这篇关于曼哈顿距离C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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