mid-kid
2 years ago
commit
c323acf703
4 changed files with 2313 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||
CXXFLAGS := -std=c++11 -Wall -Wextra -O2 |
|||
|
|||
progs := $(patsubst %.cc,%,$(wildcard *.cc)) |
|||
|
|||
.PHONY: all |
|||
all: $(addsuffix _output.txt,$(progs)) |
|||
|
|||
.PHONY: clean |
|||
clean: |
|||
rm -f $(progs) $(addsuffix _test.txt,$(progs)) |
|||
|
|||
.PHONY: ok-% |
|||
ok-%: %_test.txt |
|||
@cp -v $< $*_output.txt |
|||
|
|||
.PHONY: test-% |
|||
test-%: %_output.txt |
|||
|
|||
%_output.txt: %_test.txt |
|||
@test -f $@ || (echo $<:; cat $<) |
|||
@test -f $@ && (diff -u $@ $< && touch $@) |
|||
|
|||
$(addsuffix _test.txt,$(progs)): %_test.txt: % |
|||
./$< < $*_input.txt > $@ |
@ -0,0 +1,41 @@ |
|||
#include <iostream> |
|||
#include <vector> |
|||
#include <algorithm> |
|||
|
|||
using namespace std; |
|||
|
|||
vector<unsigned> parse() |
|||
{ |
|||
vector<unsigned> elves; |
|||
|
|||
string line; |
|||
unsigned elf = 0; |
|||
while (getline(cin, line)) { |
|||
if (line.empty()) { |
|||
elves.push_back(elf); |
|||
elf = 0; |
|||
continue; |
|||
} |
|||
elf += stoul(line); |
|||
} |
|||
|
|||
sort(elves.begin(), elves.end(), greater<int>()); |
|||
return elves; |
|||
} |
|||
|
|||
unsigned p1(vector<unsigned> &input) |
|||
{ |
|||
return input[0]; |
|||
} |
|||
|
|||
unsigned p2(vector<unsigned> &input) |
|||
{ |
|||
return input[0] + input[1] + input[2]; |
|||
} |
|||
|
|||
int main() |
|||
{ |
|||
auto input = parse(); |
|||
cout << p1(input) << endl; |
|||
cout << p2(input) << endl; |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,2 @@ |
|||
69836 |
|||
207968 |
Loading…
Reference in new issue