-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.cs
More file actions
76 lines (64 loc) · 2.48 KB
/
Library.cs
File metadata and controls
76 lines (64 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Hashcode2020CSharp
{
class Library
{
public int timeSignUp { get; set; }
public int timeScan { get; set; } // Time needed to scan all books
public int booksPerDay { get; set; }
public int id { get; set; }
public List<Book> books { get; set; }
public int points { get; set; }
public double factor { get; set; }
public Library(int[] fl, List<Book> sl, int id)
{
timeSignUp = fl[1];
booksPerDay = fl[2];
this.id = id;
books = sl.OrderByDescending(x => x.value).ToList();
SetTimeScan();
CalculatePoints();
}
public void SetTimeScan() { timeScan = (int)Math.Round((double)books.Count / booksPerDay, 0, MidpointRounding.AwayFromZero); }
public void SetTimeScan(int days) { timeScan = days; }
public void CalculatePoints()
{
points = 0;
foreach(Book b in books)
{
points += b.value;
}
}
public void SetFactor(int daysLeft)
{
/*
* First case: this library have time enough to send all books, library will set it factor with all books
* Second case: this library don't have time enough to send all books, library will set it factor with the books it can send and delete the rest of books
* Third case: this library use all time left with signup process, factor will be 0 in order to became the last library
*/
if(daysLeft > timeSignUp + timeScan)
{
CalculatePoints();
factor = points / (timeSignUp + timeScan);
} else if(daysLeft > timeSignUp)
{
SetTimeScan(daysLeft - timeSignUp);
int maxSendBooks = timeScan * booksPerDay;
if (maxSendBooks < books.Count)
{
books.RemoveRange(maxSendBooks, books.Count - maxSendBooks);
}
CalculatePoints();
factor = points / (timeSignUp + timeScan);
} else
{
factor = 0;
}
}
public void RemoveItemsAlreadyScanned(List<Book> alreadyScanned) { foreach (Book bk in alreadyScanned) books.Remove(books.Find(x => x.id == bk.id)); }
}
}