-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_04.cpp
38 lines (36 loc) · 938 Bytes
/
day_04.cpp
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
// Advent of Code 2017
// Day 04 - High-Entropy Passphrases
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <algorithm>
int main(int argc, char* argv[])
{
int validcount = 0;
std::string row;
while (std::getline(std::cin,row) && row.length()>0) {
std::stringstream str(row);
std::vector<std::string> words;
std::string pass;
bool INVALID = false;
while (str >> pass) {
// Uncomment to sort individual words, so we catch 'anagrams'
//std::sort(pass.begin(),pass.end());
if (std::find(words.begin(),words.end(),pass)==words.end()) {
// push back any words we don't already have
words.push_back(pass);
} else {
// we found a repeated word, INVALID
std::cout << pass << " invalid on " << row << std::endl;
INVALID=true;
}
}
//
if (!INVALID)
validcount++;
}
std::cout << "Valid count is " << validcount << std::endl;
return 0;
}