-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
50 lines (39 loc) · 1.76 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
namespace MagazineAPI
{
class Program
{
private static readonly ApiClient client = new ApiClient();
private static List<string> Categories;
private static List<Subscriber> Subscribers;
private static Dictionary<string, List<Magazine>> MagazinesByCategory = new Dictionary<string, List<Magazine>>();
static void Main(string[] args)
{
Categories = client.GetCategoriesAsync().Result;
Subscribers = client.GetSubscribersAsync().Result;
foreach (var category in Categories)
{
List<Magazine> magazines = client.GetMagazinesWithCategoryAsync(category).Result;
MagazinesByCategory[category] = magazines;
}
List<Subscriber> subscribersToAllCategories = Subscribers.FindAll(SubscribesToAllCategories);
List<string> subscriberIds = new List<string>();
foreach (var subscriber in subscribersToAllCategories)
subscriberIds.Add(subscriber.id);
PostResult resultObj = client.SubmitAnswerAsync(subscriberIds).Result;
Console.WriteLine($"Answer correct: {resultObj.answerCorrect}");
Console.WriteLine($"Execution time: {resultObj.totalTime}");
}
private static bool SubscribesToAllCategories(Subscriber s)
{
int numCategories = 0;
foreach (var category in Categories)
{
if (s.magazineIds.Exists((int id) => MagazinesByCategory[category].Exists((Magazine m) => m.id == id)))
numCategories++;
}
return numCategories == Categories.Count;
}
}
}