Răspuns :
Răspuns:
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
int Problema_1(vector<vector<int>> matrix,int n)
{
int negre=0;
for (int i = 0; i < n; i++)
if (matrix[i][0] == 1)
negre++;
return negre;
}
int Problema_2(vector<vector<int>> matrix, int n, int m)
{
int aria = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if ((matrix[i][j] != 0)&&((i+1)*(j+1)>aria))
{
aria = (i + 1) * (j + 1);
}
return aria;
}
int main() {
int c, n, m, a;
fstream f("cort.in");
ofstream out("cort.out");
f >> c >> n >> m;
vector<vector<int> > matrix;
if ((n < 0) || (m > 1000))
return -1;
for (int i = 0; i < n; i++) {
vector<int> v;
for (int j = 0; j < m; j++)
{
f >> a;
v.push_back(a);
}
matrix.push_back(v);
}
if (matrix[0][0] == 0)
return -1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m - 1; j++)
for (int k = j + 1; k < m; k++)
if ((matrix[i][j] == 0) && (matrix[i][k] == 1))
{
swap(matrix[i][j], matrix[i][k]);
k = m;
}
for (int j = 0; j < m; j++)
for (int i = 0; i < n - 1; i++)
for (int k = i + 1; k < n; k++)
if ((matrix[i][j] == 0) && (matrix[k][j] == 1))
{
for (int l = 0; l < m; l++)
swap(matrix[i][j], matrix[k][j]);
k = n;
}
if (c == 1)
out << Problema_1(matrix, n);
else
if (c == 2)
out << Problema_2(matrix, n, m);
}
La restrictie ai 1<=n<=m<1000
Exemplul nu indeplineste conditia deoare n=6 si m=5 => n>m deci nu am pus restrictia asta;
Daca vrei o poti adauga in primul if.