Kattis Competiton (I've Been Everywhere, Man)
Note:
This code was written during a crunch period and isn't perfect. There will
be some errant spacing, some files will be
using namespace std,
etc. But it's all still usable and can be a
handy guideline if you're learning Data Structures.
#include <vector>
#include <map>
#include <string>
using namespace std;
class Everywhere
{
public:
Everywhere(vector<string> lns)
{
lines = lns;
getCaseCount();
for (int i = 0; i < casecnt; i++)
{
readCase();
}
}
vector<string> lines;
int casecnt = 0;
int index = 0;
int citycount = 0;
void getCaseCount()
{
casecnt = stoi(lines[index]);
index++;
}
void readCase()
{
int citycount = stoi(lines[index]);
vector<string> cities;
map<string, bool> been;
index++;
for (int i = 0; i < citycount; i++)
{
if (index < lines.size())
{
if (!been[lines[index]])
{
cities.push_back(lines[index]);
been[lines[index]] = true;
}
index++;
}
}
citycount = cities.size();
cout << citycount << endl;
}
};
int main(int argc, char *argv[])
{
string line;
vector<string> lines;
while (getline(cin, line))
{
lines.push_back(line);
}
Everywhere ev(lines);
}