C++11. Почему выдается ошибка? В код сильно не вникайте, алгоритм правильный. Ошибка request for member 'sort' in 'vec', which is of non-class type 'std::pair, int> [1050]' при сортировке. #include
#include
using namespace std;
int A[505][505];
pair, int> vec[1050];
bool comp(pair, int> a, pair, int> b) {
if(a.first.size() != b.first.size()) return a.first.size() < b.first.size();
else {
int amax = -1, asum = 0;
for(auto it = a.first.begin(); it != a.first.end(); it++) {
asum += *it;
amax = max(amax, *it);
}
int bmax = -1, bsum = 0;
for(auto it = b.first.begin(); it != b.first.end(); it++) {
bsum += *it;
bmax = max(bmax, *it);
}
return asum < bsum or (asum == bsum and amax < bmax);
}
}
main() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> A[i][j];
}
}
for(int d = 2; d <= m + n; d++) {
int f;
for(f = (m < d ? d - m + 1 : 1); f <= d; f++) {
vec[d].first.push_back(A[f][d - f]);
}
vec[d].second = d - 1;
}
vec.sort(vec + 1, vec + m + n + 1, comp);
for(int i = 1; i <= n + m; i++) {
cout << vec[i].second << " ";
}
}
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Copyright © 2024 SCHOLAR.TIPS - All rights reserved.