今天写的时候就比较晚了已经,晚上去跑了一会步,淋着小雨,还是很惬意的;
发现vector还是可以直接排序的,直接sort就好;
两种输入,昨天被那个学长骂了以后今天变得贼乖就用下标表示数组,不过也可以,因为每行的元素也不多;
if大法好~~b( ̄▽ ̄)d
代码如下:
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1000;
int n;
float mid;
int main() {
cin >> n;
vector<int>s[N];
int t = 0;
while (t++ < n) {
scanf_s("(%d,%d)", s[t][1], s[t][0]);
//第二种输入方式,较为麻烦;
/*
cin >> j;
s[t].push_back(j);
cin >> j;
s[t].insert(s->begin(), j);
*/
}
sort(s->begin(), s->end());
mid = (s[0][1] + s[1][1]) / 2;
int i = 1, j = 0, mid1 = 0;
while (i < n) {
j = i + 1;
if (s[i][1] == s[j][1]) {
mid1 = (s[i][1] + s[j][1]) / 2;
if (mid == mid1) {
i += 2;
}
else {
cout << "inexist" << endl;
return 0;
}
}
else {
if (mid == s[i][1])
i++;
else {
cout << "inexist" << endl;
return 0;
}
}
}
cout << "mid is " << mid << endl;
return 0;
}