# 今日头条2018秋招笔试题（未完待续）

#include <iostream>
#include <vector>
#include <string>
using namespace std;
void helper(const vector<vector<int>>& array, vector<vector<bool>>& check, int& cnt, int i, int j) {
if (i < 0 || i >= array.size() || j < 0 || j >= array[0].size()) {
return;
}
if (array[i][j] == 1 && !check[i][j]) {
++cnt;
check[i][j] = true;
helper(array, check, cnt, i-1, j-1);
helper(array, check, cnt, i-1, j);
helper(array, check, cnt, i-1, j+1);
helper(array, check, cnt, i, j-1);
helper(array, check, cnt, i, j+1);
helper(array, check, cnt, i+1, j-1);
helper(array, check, cnt, i+1, j);
helper(array, check, cnt, i+1, j+1);
} else {
return;
}
}
int main() {
int M, N;
char b;
cin >> M >> b >> N;
vector<vector<int>> array(M, vector<int>(N, 0));
vector<vector<bool>> check(M, vector<bool>(N, false));
int tmp;
int i, j;
for (i = 0; i < M; ++i) {
for (j = 0; j < N - 1; ++j) {
cin >> tmp;
cin >> b;
array[i][j] = tmp;
}
if (j == N - 1) {
cin >> tmp;
array[i][j] = tmp;
}
}
int P = 0;
int Q = 0;
int cnt = 0;
for (int i = 0; i < M; ++i) {
for (int j = 0; j < N; ++j) {
if (array[i][j] == 1 && !check[i][j]) {
helper(array, check, cnt, i, j);
Q = max(Q, cnt);
cnt = 0;
++P;
}
}
}
cout << P << "," << Q << endl;
}

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T;
vector<pair<int, int>> array;
pair<int, int> tmp;
string s;
for (int i = 0; i < T+1; ++i) {
getline(cin, s);
istringstream is (s);
int inter1, inter2;
char ch;
while (is >> inter1 >> ch >> inter2)
{
tmp.first = inter1;
tmp.second = inter2;
array.push_back(tmp);
is >> ch;
}
}
if (array.size() == 0) {
return 0;
}

sort(array.begin(), array.end());

vector<pair<int, int>> res;
int a1 = array[0].first;
int b1 = array[0].second;

for (int i = 1; i < array.size(); ++i) {
int a = array[i].first;
int b = array[i].second;
if (a <= b1) {
b1 = max(b1, b);
} else {
res.push_back(pair<int, int>(a1, b1));
a1 = a;
b1 = b;
}
}
res.push_back(pair<int ,int>(a1, b1));

for (int i = 0; i < res.size() - 1; ++i) {
cout << res[i].first << "," << res[i].second << ";";
}
cout << res[res.size() - 1].first << "," << res[res.size() - 1].second;
return 0;
}