任何人都可以帮我解决这个问题 [英] Can anyone help me with this problem

查看:72
本文介绍了任何人都可以帮我解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.IO;

namespace ProfitCalculator
{
/// ==============================================================================

public class RangeFinder
{
/// <summary>
/// Performs calculations to find the start and end of the "best" data sequence
/// which has the greatest sum of data values over that sequence.
///
/// <param name="data">the data to be examined
/// <param name="bestStart">the start point found by the search
/// <param name="bestEnd">the end point found by the search
/// <param name="bestTotal">the sum of data values over that range
/// <param name="loops">the number of executions of the inner loop
public static void MaxSum1(double[] data, out int bestStart,
out int bestEnd, out double bestTotal, out int loops)
{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
for
(int i = 0; i < data.Length; i++)
{
Console.WriteLine("Value {0}", data[i]);
}

}
public static void MaxSum2(double[] data, out int bestStart,
out int bestEnd, out double bestTotal, out int loops)
{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
}
public static void MaxSum3(double[] data, out int bestStart,
out int bestEnd, out double bestTotal, out int loops)
{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
}

/// ==============================================================================
/// <summary>
/// Tests the Profits Calculator
///
class Test
{
/// <summary>
/// The main entry point for the application.
///
static void Main()
{
double[] data;
int bestStart, bestEnd;
double bestTotal;
int loops;

/// name of the file and the number of readings
string filename = "week52.txt";
int items = 52;

data = new double[items]; /// create the data array

try
{
TextReader textIn = new StreamReader(filename);
for (int i = 0; i < items; i++) /// input and store the data values
{
string line = textIn.ReadLine();
data[i] = double.Parse(line);
}
textIn.Close();
}
catch
{
Console.WriteLine("File Read Failed");
return;
}

/// ---------------------------------------------------------------------
/// call the process method to find the best profit period
/// ---------------------------------------------------------------------

RangeFinder.MaxSum1(
data, out bestStart, out bestEnd, out bestTotal, out loops);

Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
bestStart, bestEnd, bestTotal, loops);

RangeFinder.MaxSum2(
data, out bestStart, out bestEnd, out bestTotal, out loops);

Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
bestStart, bestEnd, bestTotal, loops);

RangeFinder.MaxSum3(
data, out bestStart, out bestEnd, out bestTotal, out loops);

Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
bestStart, bestEnd, bestTotal, loops);







问题是如何破译以下伪代码:





对于每个可能的起始位置//每个阵列index依次

对于每个可能的结束位置//从当前开始的数组的其余部分

{将小计设置为0对于子序列中的每个值//当前开始和结束之间添加利润值到小计

当小计超过当前最佳总数时更新子查询信息

}



最初你可以忽略loops变量显示为MaxSum方法的输出参数,只关注创建一个返回bestStart,bestEnd和bestTotal值的程序。请注意,您可以使用数据数组的Length属性来确定数据的大小



我正在努力理解或破译这可以让任何人帮助



我尝试过:



{

bestTotal = 0 ;

bestStart = 0;

bestEnd = 0;

loops = 0;

for

(int i = 0; i< data.Length; i ++)

{

Console.WriteLine(Value {0},data [i ]);

}



}




the question is how to decipher this the following pseudo code:


For every possible start position // every array index in turn
For every possible end position // rest of array from current start
{ Set subtotal to 0 For every value in subseq // between current start and end Add profit value to subtotal
Update subseq info when subtotal exceeds current best total
}

Initially you can ignore the loops variable shown as an output parameter of the MaxSum method, and just concentrate on creating a program which returns the bestStart, bestEnd and bestTotal values. Note that you can use the Length property of the data array to determine how large it is

im struggling to understand or decipher this can anyone help

What I have tried:

{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
for
(int i = 0; i < data.Length; i++)
{
Console.WriteLine("Value {0}", data[i]);
}

}

推荐答案

阅读说明,得到纸和笔,并手动尝试。

结合问题的其余部分 - 我们没有 - 它应该有所帮助。



我们无法从你的家庭作业片段中找出你的导师要求你做的事情 - 它似乎是s获得最高利润小计,但我们不知道这些规则是什么。



所以请阅读整个问题,并亲自尝试 - 当你让它工作它应该很容易翻译成计算机代码!
Read the instructions, get a paper and pencil, and try it manually.
Combined with the rest of the question - which we don't have - it should make some sense.

We can't work out from that fragment of your homework exactly what your tutor is asking you do to - it seems to be searching for a "highest profit subtotal" but we have no idea what the rules for that are.

So read the whole question, and try it for yourself - when you have it working it should be easy to translate into computer code!


这篇关于任何人都可以帮我解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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