mid-kid
2 years ago
6 changed files with 1104 additions and 1 deletions
@ -0,0 +1,58 @@ |
|||
#include <iostream> |
|||
#include <vector> |
|||
#include <array> |
|||
|
|||
using namespace std; |
|||
|
|||
class Range { |
|||
public: |
|||
unsigned min; |
|||
unsigned max; |
|||
|
|||
bool contains(const Range &in) { |
|||
return min <= in.min && max >= in.max; |
|||
} |
|||
|
|||
bool overlaps(const Range &in) { |
|||
return (min <= in.min && in.min <= max) |
|||
|| (min <= in.max && in.max <= max) |
|||
|| (in.min <= min && min <= in.max) |
|||
|| (in.min <= max && max <= in.max); |
|||
} |
|||
}; |
|||
|
|||
typedef vector<array<Range, 2>> Input; |
|||
|
|||
Input parse() |
|||
{ |
|||
Input data; |
|||
for (string line; getline(cin, line);) { |
|||
array<Range, 2> entry; |
|||
sscanf(line.c_str(), "%u-%u,%u-%u", |
|||
&entry[0].min, &entry[0].max, |
|||
&entry[1].min, &entry[1].max); |
|||
data.push_back(entry); |
|||
} |
|||
return data; |
|||
} |
|||
|
|||
unsigned p1(const Input &input) |
|||
{ |
|||
unsigned count = 0; |
|||
for (auto i : input) if (i[0].contains(i[1]) || i[1].contains(i[0])) count++; |
|||
return count; |
|||
} |
|||
|
|||
unsigned p2(const Input &input) |
|||
{ |
|||
unsigned count = 0; |
|||
for (auto i : input) if (i[0].overlaps(i[1])) count++; |
|||
return count; |
|||
} |
|||
|
|||
int main() |
|||
{ |
|||
Input input = parse(); |
|||
cout << p1(input) << endl; |
|||
cout << p2(input) << endl; |
|||
} |
@ -0,0 +1,12 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
from sys import stdin |
|||
data = [(range(int(a1), int(a2)+1), range(int(b1), int(b2)+1)) |
|||
for (a1, a2), (b1, b2) in [(a.split("-"), b.split("-")) |
|||
for a, b in [x.split(",") for x in stdin.readlines()]]] |
|||
print(sum(all(x in b for x in a) or all(x in a for x in b) for a, b in data)) |
|||
print(sum(bool(set(a) & set(b)) for a, b in data)) |
|||
|
|||
for a, b in data: |
|||
if set(a) & set(b): |
|||
print((a,b)) |
File diff suppressed because it is too large
@ -0,0 +1,2 @@ |
|||
599 |
|||
928 |
@ -0,0 +1,31 @@ |
|||
#include <iostream> |
|||
#include <vector> |
|||
|
|||
using namespace std; |
|||
|
|||
typedef vector<unsigned> Input; |
|||
|
|||
Input parse() |
|||
{ |
|||
Input data; |
|||
return data; |
|||
} |
|||
|
|||
unsigned p1(const Input &input) |
|||
{ |
|||
(void)input; |
|||
return 0; |
|||
} |
|||
|
|||
unsigned p2(const Input &input) |
|||
{ |
|||
(void)input; |
|||
return 0; |
|||
} |
|||
|
|||
int main() |
|||
{ |
|||
Input input = parse(); |
|||
cout << p1(input) << endl; |
|||
cout << p2(input) << endl; |
|||
} |
Loading…
Reference in new issue