-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid0022.c
More file actions
40 lines (28 loc) · 772 Bytes
/
id0022.c
File metadata and controls
40 lines (28 loc) · 772 Bytes
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
// Licensed under the MIT License.
// Names Scores
#include <string.h>
#include "../lib/euler.h"
#include "../lib/string_collection.h"
#include "../lib/sort.h"
int main(void)
{
long sum = 0;
struct List names;
clock_t start = clock();
euler_ok(list(&names, sizeof(String), 5000));
euler_ok(string_collection_deserialize(&names, stdin));
qsort(names.items, names.count, names.itemSize, string_comparer);
String* begin = names.items;
for (size_t i = 0; i < names.count; i++)
{
int rank = 0;
for (char* p = begin[i]; *p; p++)
{
rank += *p - 'A' + 1;
}
sum += rank * (i + 1);
free(begin[i]);
}
finalize_list(&names);
return euler_submit(22, sum, start);
}