aboutsummaryrefslogtreecommitdiff
path: root/challenge-270/zapwai/python/ch-1.py
blob: cee3a0cdfce05ff44602087f0063ecace29da89a (plain)
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
matrix = [ [1, 0, 0],
	   [0, 0, 1],
	   [1, 0, 0],
	  ]

matrix2 = [ [1, 0, 0],
	    [0, 1, 0],
	    [0, 0, 1],
	   ]

def is_special(m, M, N, i, j): 
    if m[i][j] != 1:
        return 0 
    for k in range(M):
        if k == i:
            continue
        if m[k][j] != 0:
            return 0
    for k in range (N):
        if k == j:
            continue
        if m[i][k] != 0:
            return 0 
    return 1

def proc(m):
    M = len(m)
    N = len(m[0])
    print("Input: \nm = ")
    cnt = 0
    for i in range(M):
        for j in range(N):
            print(m[i][j], end='')
            if is_special(m, M, N, i, j):
                cnt += 1
        print("")
    print("Output:", cnt)

proc(matrix)
proc(matrix2)