-
Notifications
You must be signed in to change notification settings - Fork 0
/
task6.c
81 lines (62 loc) · 1.67 KB
/
task6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[100][100]; /**< Èñõîäíàÿ ìàòðèöà */
int s[100], index[100];/**< Ìàòðèöà ñóìì è èíäåêñîâ */
unsigned int n,i,j,t;
FILE *f = fopen("input.txt", "r");
fscanf(f,"%u", &n);
//printf("input size of matrix ");
//printf("input elements of matrix \n");
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
fscanf(f,"%d", &a[i][j]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++)
printf("%d ", a[i][j]);
printf("\n");
} // Âûâîä ââåäåííîé ìàòðèöû
for (i = 0; i < n; i++) {
s[i] = 0;
for (j = 0; j < n; j++)
if ((a[i][j] > 0)&&(a[i][j] % 2 == 0))
s[i] += a[i][j];
// printf("%d %d \n", i ,s[i]);
}
printf("\n \n");
for (i = 0; i < n; i++) index[i] = i;
int flag = 1;
do {
flag = 1;
for (i = 0; i < n - 1; i++)
if (s[i]<s[i+1]) {
t = s[i];
s[i] = s[i+1];
s[i+1] = t;
t = index[i];
index[i] = index[i + 1];
index[i + 1] = t;
flag = 0;
}
} while (flag);
//for (i = 0; i < n; i ++)
// printf("%d %d %d \n",i, index[i], s[i]);
//printf("\n \n");
for (i = 0; i < n; i ++)
if (s[i] != -1) {
for (j = 0; j < n; j ++){
t = a[i][j];
a[i][j] = a[index[i]][j];
a[index[i]][j] = t;
}
s[index[i]]=-1;
s[i]=-1;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++)
printf("%d ", a[i][j]);
printf("\n");
}
return 0;
}