-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2006_customs.cpp
96 lines (82 loc) · 2.82 KB
/
aoc2006_customs.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* \\ /`/`` */
/* ~\o o_ 0 0\ */
/* / \__) (u ); _ _ */
/* / \/ \/ / \ \/ \/ \ */
/* /( . . ) ( )\ */
/* / \_____/ \_______/ \ */
/* [] [] [[] [[] *. */
/* []] []] [[] [[] */
/* */
/* ****************************************************************** nuo *** */
#include "iostream"
#include "utility"
#include "vector"
#include "map"
#include "set"
int size_everyone(std::vector<std::string> v);
int size_anyone(std::vector<std::string> v);
// DRIVE
int main()
{
std::vector<std::string> arr;
std::string s;
int everyone, anyone;
anyone = everyone = 0;
while (std::getline(std::cin, s))
{
if (s == "")
{
everyone += size_everyone(arr);
anyone += size_anyone(arr);
arr.clear();
}
else arr.push_back(s);
}
everyone += size_everyone(arr);
anyone += size_anyone(arr);
std::cout << "Star 1 : " << anyone << std::endl;
std::cout << "Star 2 : " << everyone << std::endl;
return (0);
}
//
int size_everyone(std::vector<std::string> v)
{
std::map<char,int>::iterator it;
std::map<char, int> q;
int len;
int i, j;
i = -1;
while (++i < (int) v.size())
{
j = -1;
while (++j < (int) v[i].length())
{
it = q.find(v[i][j]);
if (it == q.end()) q.insert(std::make_pair(v[i][j], 1));
else q[v[i][j]] += 1;
}
}
len = 0;
it = q.begin();
while (it != q.end())
{
if (it->second == (int) v.size()) len++;
it++;
}
return (len);
}
int size_anyone(std::vector<std::string> v)
{
std::set<char> q;
int i;
int j;
i = -1;
while (++i < (int) v.size())
{
j = -1;
while (++j < (int) v[i].length()) q.insert(v[i][j]);
}
return ((int) q.size());
}