Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ProfitCalculator
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. public static void MaxSum(double[] data, out int bestStart,
  14. out int bestEnd, out double bestTotal, out int loops)
  15. {
  16. bestTotal = 0;
  17. bestStart = 0;
  18. bestEnd = 0;
  19. loops = 0;
  20. int tempStart = 0;
  21. double subTotal = 0;
  22.  
  23.  
  24. for (int i = 0; i < data.Length; i++)
  25. {
  26. subTotal = 0;
  27. for (int z = i; z < data.Length; z++)
  28. {
  29. subTotal = 0;
  30. tempStart = z;
  31. for (int j = z; j < data.Length; j++)
  32. {
  33. subTotal += data[j];
  34. if (subTotal > bestTotal)
  35. {
  36. bestTotal = subTotal;
  37. bestStart = tempStart;
  38. bestEnd = j;
  39. }
  40. loops++;
  41. }
  42. }
  43.  
  44. Console.WriteLine("Value {0} {1}", data[i], bestTotal);
  45.  
  46. }
  47. }
  48.  
  49. public static void MaxSum2(double[] data, out int bestStart,
  50. out int bestEnd, out double bestTotal, out int loops)
  51. {
  52. bestTotal = 0;
  53. bestStart = 0;
  54. bestEnd = 0;
  55. loops = 0;
  56. double subTotal = 0;
  57.  
  58.  
  59. for (int i = 0; i < data.Length; i++)
  60. {
  61. subTotal = 0;
  62. for (int z = i; z < data.Length; z++)
  63. {
  64. subTotal += data[z];
  65. if (subTotal > bestTotal)
  66. {
  67. bestTotal = subTotal;
  68. bestStart = i;
  69. bestEnd = z;
  70. }
  71. loops++;
  72. }
  73.  
  74. Console.WriteLine("Value {0} Value {1}", data[i], subTotal);
  75.  
  76. }
  77. }
  78.  
  79.  
  80. public static void MaxSum3(double[] Data, out int BestStart,
  81. out int BestEnd, out double BestTotal, out int loops)
  82. {
  83. BestTotal = 0;
  84. BestStart = 0;
  85. BestEnd = 0;
  86. loops = 0;
  87. double Total = 0;
  88. int startPos = 0;
  89.  
  90.  
  91. for (int i = 0; i < Data.Length; i++)
  92. {
  93. Total += Data[i];
  94.  
  95. Console.WriteLine("Value {0}, Value {1}", Data[i], Total);
  96.  
  97.  
  98. if (Total > BestTotal)
  99. {
  100. BestStart = startPos;
  101. BestEnd = i;
  102. BestTotal = Total;
  103. }
  104.  
  105. if (Total < 0)
  106. {
  107. startPos = i + 1;
  108. Total = 0;
  109. }
  110. loops++;
  111. }
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement