#include <iostream>
using namespace std;
bool check(int *a_, int m_){
for(int i = 0; i < m_; i++)
if(!(*(a_ + i) & 1))
return false;
return true;
}
int absSum(int *a_, int m_){
int sum = 0;
sum += abs(*(a_ + i));
return sum;
void solve(){
int n, m;
cin >> n >> m;
int a[n][m];
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
pair<int, int> res = {-1, -1};
if(check(a[i], m) && absSum(a[i], m) > res.second)
res = {i, absSum(a[i], m)};
if(res.first < 0)
cout << "There are no suitable lines in the given array";
else
cout << (res.first + 1);
int main(){
solve();
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
bool check(int *a_, int m_){
for(int i = 0; i < m_; i++)
if(!(*(a_ + i) & 1))
return false;
return true;
}
int absSum(int *a_, int m_){
int sum = 0;
for(int i = 0; i < m_; i++)
sum += abs(*(a_ + i));
return sum;
}
void solve(){
int n, m;
cin >> n >> m;
int a[n][m];
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
pair<int, int> res = {-1, -1};
for(int i = 0; i < n; i++)
if(check(a[i], m) && absSum(a[i], m) > res.second)
res = {i, absSum(a[i], m)};
if(res.first < 0)
cout << "There are no suitable lines in the given array";
else
cout << (res.first + 1);
}
int main(){
solve();
}