-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
76 lines (69 loc) · 1.44 KB
/
main.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
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
struct Pass {
int from;
int to;
char c;
std::string pass;
};
std::ostream &operator<<(std::ostream &out, const Pass &pass)
{
out << pass.from << '-' << pass.to << ' ' << pass.c << ": " << pass.pass;
return out;
}
int readNum(std::istream &in)
{
int r = 0;
do {
r = r * 10 + (in.get() - '0');
} while (isdigit(in.peek()));
return r;
}
std::vector<Pass> read()
{
std::ifstream in { "input.txt" };
int n;
in >> n;
in.get(); // _:
std::vector<Pass> v(n);
for (auto &p : v) {
p.from = readNum(in);
in.get(); // -
p.to = readNum(in);
in.get(); // _
in >> p.c;
in.get(); // :
in.get(); // _:
in >> p.pass;
in.get(); // _:
}
return v;
}
int f1(const std::vector<Pass> &v, int n)
{
int res = 0;
for (const auto &e : v) {
auto count = std::count(e.pass.begin(), e.pass.end(), e.c);
if (count >= e.from && count <= e.to)
++res;
}
return res;
}
int f2(const std::vector<Pass> &v, int n)
{
int res = 0;
for (const auto &e : v) {
res += ((e.pass[e.from - 1] == e.c) ^ (e.pass[e.to - 1] == e.c));
}
return res;
}
int main()
{
const auto v = read();
std::cout << f1(v, v.size()) << std::endl;
std::cout << f2(v, v.size()) << std::endl;
}