Advertisement
Dubwyn

Untitled

Jul 8th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace GameSkeleton
  9. {
  10.     class CapacityList
  11.     {
  12.  
  13.         private const int InitialCapacity = 2;
  14.  
  15.         private Pair[] items;
  16.  
  17.        
  18.  
  19.         private int startIndex = 0; //показва първият индекс, от който започваме да сумираме текущите елементи
  20.  
  21.         private int nextIndex = 0; //показва поредният индекс, на който можем да поставим елемент
  22.  
  23.  
  24.  
  25.         public CapacityList(int capacity = InitialCapacity)
  26.  
  27.         {
  28.  
  29.             this.items = new Pair[capacity];
  30.  
  31.         }
  32.  
  33.  
  34.  
  35.         public int Count
  36.  
  37.         {
  38.  
  39.             get;
  40.  
  41.             private set;
  42.  
  43.         }
  44.  
  45.  
  46.  
  47.         public Pair SumIntervalPairs()
  48.  
  49.         {
  50.             return new Pair(0,0);
  51.             //TODO: сумирайте двойките от startIndex до nextIndex
  52.  
  53.         }
  54.  
  55.  
  56.  
  57.         public Pair Sum()
  58.  
  59.         {
  60.             Pair finalSum = new Pair(0,0);
  61.             for (int i = startIndex; i < this.Count; i++)
  62.             {
  63.                 finalSum.First = items[i].First;
  64.                 finalSum.Last = items[i].Last;
  65.             }
  66.             //TODO: сумирайте двойките от 0 до this.Count – всички двойки, които имат право да участват в класирането
  67.             return finalSum;
  68.         }
  69.  
  70.  
  71.  
  72.         public void Add(Pair item)
  73.  
  74.         {
  75.             if (nextIndex == items.Length)
  76.             {
  77.                 Pair finalSet = new Pair(0,0);
  78.                 for (int i = startIndex; i < items.Length; i++)
  79.                 {
  80.                    
  81.                         finalSet.First += items[i].First;
  82.                         finalSet.Last += items[i].Last;
  83.                 }
  84.                
  85.                 nextIndex = startIndex;
  86.                 items[nextIndex] = finalSet;
  87.                 nextIndex++;
  88.                 startIndex++;
  89.  
  90.             }
  91.            
  92.             items[nextIndex] = item;
  93.             nextIndex++;
  94.  
  95.  
  96.         }
  97.  
  98.  
  99.         public void PrintCurrentState()
  100.  
  101.         {
  102.             for (int i = 0; i < nextIndex; i++)
  103.             {
  104.                 Console.WriteLine($"({items[i].First}, {items[i].Last})");
  105.             }
  106.             //TODO: отпечатайте всички двойки от 0 до nextIndex
  107.  
  108.         }
  109.  
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement