Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProfitCalculator
- {
- class Program
- {
- static void Main(string[] args)
- {
- public static void MaxSum(double[] data, out int bestStart,
- out int bestEnd, out double bestTotal, out int loops)
- {
- bestTotal = 0;
- bestStart = 0;
- bestEnd = 0;
- loops = 0;
- int tempStart = 0;
- double subTotal = 0;
- for (int i = 0; i < data.Length; i++)
- {
- subTotal = 0;
- for (int z = i; z < data.Length; z++)
- {
- subTotal = 0;
- tempStart = z;
- for (int j = z; j < data.Length; j++)
- {
- subTotal += data[j];
- if (subTotal > bestTotal)
- {
- bestTotal = subTotal;
- bestStart = tempStart;
- bestEnd = j;
- }
- loops++;
- }
- }
- Console.WriteLine("Value {0} {1}", data[i], bestTotal);
- }
- }
- 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;
- double subTotal = 0;
- for (int i = 0; i < data.Length; i++)
- {
- subTotal = 0;
- for (int z = i; z < data.Length; z++)
- {
- subTotal += data[z];
- if (subTotal > bestTotal)
- {
- bestTotal = subTotal;
- bestStart = i;
- bestEnd = z;
- }
- loops++;
- }
- Console.WriteLine("Value {0} Value {1}", data[i], subTotal);
- }
- }
- 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;
- double Total = 0;
- int startPos = 0;
- for (int i = 0; i < Data.Length; i++)
- {
- Total += Data[i];
- Console.WriteLine("Value {0}, Value {1}", Data[i], Total);
- if (Total > BestTotal)
- {
- BestStart = startPos;
- BestEnd = i;
- BestTotal = Total;
- }
- if (Total < 0)
- {
- startPos = i + 1;
- Total = 0;
- }
- loops++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement