From 73e28533374104587c3baf42b29ff6094f4d54b9 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Tue, 5 Dec 2017 12:14:46 +0100 Subject: day04 --- day04.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 day04.cc (limited to 'day04.cc') diff --git a/day04.cc b/day04.cc new file mode 100644 index 0000000..85ae224 --- /dev/null +++ b/day04.cc @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace anagram { + struct is_anagram { + bool operator()(const string &a, const string &b) const { + return is_permutation(begin(a), end(a), begin(b)); + } + }; + + struct unordered_hash { + size_t operator()(const string &a) const { + return accumulate(begin(a), end(a), 0); + } + }; + + using set = unordered_set; +} + +int +main() +{ + string line; + int p1 = 0, p2 = 0; + + while (getline(cin, line)) { + istringstream is1{line}, is2{line}; + set words{istream_iterator(is1), + istream_iterator()}; + anagram::set awords{words.cbegin(), words.cend()}; + size_t wcount = distance(istream_iterator(is2), + istream_iterator()); + + if (words.size() == wcount) p1++; + if (awords.size() == wcount) p2++; + } + + cout << p1 << endl << p2 << endl; +} -- cgit 1.4.1