-
-
Save rkotov93/1231992 to your computer and use it in GitHub Desktop.
problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <malloc.h> | |
#include <limits.h> | |
int minNum(int* str, int m) { | |
int min = INT_MAX; | |
int i; | |
for (i = 0; i < m; i++) { | |
//printf("%d", str[i]); | |
if (str[i] < min) | |
min = str[i]; | |
} | |
//printf("%d\n", min); | |
return min; | |
} | |
int sumElemnts(int* mass, int n) { | |
int i; | |
int sum; | |
for (i = 0; i < n; i++) sum += mass[i]; | |
//printf("%d\n", sum); | |
return sum; | |
} | |
int findMaxStr(int** matr, int n, int m) { | |
int i, j; | |
int minNum = 0; | |
int maxSum = 0; | |
for (i = 0; i < n; i++) | |
if (sumElemnts(matr[i], m) > maxSum) { | |
maxSum = sumElemnts(matr[i], m); | |
minNum = i; | |
} | |
//printf("%d\n", minNum); | |
return minNum; | |
} | |
int findMaxColumn(int** matr, int n, int m) { | |
int i,j; | |
int max = 0; | |
int x; | |
for (i = 0; i < m; i++) { | |
for (j = 0; j < n; j++) | |
if (matr[j,i] < 0) { | |
x = 0; | |
break; | |
} | |
if (x) | |
max = i; | |
} | |
printf("%d\n", max); | |
return max; | |
} | |
int main() { | |
int n,m; | |
int i,j; | |
int** matr; | |
int min; | |
int ans; | |
freopen("input.txt", "r", stdin); | |
freopen("output.txt", "w", stdout); | |
scanf("%d%d", &n, &m); | |
matr = (int**) malloc(n * sizeof(int)); | |
for (i = 0; i < n; i++) | |
matr[i] = (int*)malloc(m * sizeof(int)); | |
for (i = 0; i < n; i++) | |
for (j = 0; j < m; j++) scanf("%d", &matr[i][j]); | |
for (i = 0; i < n-1; i++) | |
for (j = i+1; j < n; j++) | |
if (minNum(matr[i], m) == minNum(matr[j], m)) { | |
ans = findMaxStr(matr, n, m); | |
printf("%d", ans+1); | |
return 0; | |
} | |
ans = findMaxColumn(matr, n, m); | |
printf("%d", ans+1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment