-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdata.cpp
More file actions
64 lines (51 loc) · 1.29 KB
/
data.cpp
File metadata and controls
64 lines (51 loc) · 1.29 KB
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
#include "data.h"
std::ostream& operator<<(std::ostream& os, const Coord& c)
{
return os << "(" << c.x << "," << c.y << ")";
}
std::ostream& operator<<(std::ostream& os, const Answer& c)
{
switch (c)
{
case Answer::Blank: return os << "_";
case Answer::A: return os << "A";
case Answer::B: return os << "B";
case Answer::C: return os << "C";
case Answer::D: return os << "D";
case Answer::E: return os << "E";
default: return os << "?";
}
}
std::istream& operator>>(std::istream& is, Coord& c)
{
is.exceptions(is.exceptions()|std::ios_base::badbit);
char paren1, comma, paren2;
is >> paren1 >> c.x >> comma >> c.y >> paren2;
return is;
}
bool operator==(const Coord& c1, const Coord& c2)
{
return (c1.x == c2.x && c1.y == c2.y);
}
bool operator!=(const Coord& c1, const Coord& c2)
{
return !(c1==c2);
}
bool operator<(const Coord& c1, const Coord& c2)
{
return (c1.y < c2.y || (c1.y == c2.y && c1.x < c2.x));
}
bool operator>(const Coord& c1, const Coord& c2)
{
return !(c1 < c2) && !(c1 == c2);
}
Coord Coord::operator+(const Coord& c) const
{
return Coord(x+c.x, y+c.y);
}
Coord& Coord::operator+=(const Coord& c)
{
x += c.x;
y += c.y;
return *this;
}