Problem:


Score : 200 points

Problem Statement

There is a grid of squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Each square is black or white.
The color of the square is given as an H-by-W matrix (a_{i, j}).
If a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.

Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:

Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.

It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#



Sample input:
4 4
##.#
....
##.#
.#.#


Sample output:
###
###
.##

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[]
for i in range(H):
    a.append(input())

tate=[[False]*W for i in range(H)]
yoko=[[False]*W for i in range(H)]

for i in range(H):
    if('#' in a[i]):
        for j in range(W):
            yoko[i][j]=True
for j in range(W):
    for i in range(H):
        if(a[i][j]=='#'):
            for k in range(H):
                tate[k][j]=True
            continue
for i in range(H):
    for j in range(W):
        if(tate[i][j] and yoko[i][j]):
            print(a[i][j],end='')
    if(yoko[i]!=[False]*W):
        print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

A = [a for a in A if ('#' in a)]
A = [a for a in zip(*A) if ('#' in a)]
A = zip(*A)

for a in A:
    print(''.join(a))

Submission status: Accepted

Solution code:
import numpy as np

Height, Width = map(int, input().split())
mat = [[0 for i in range(Width)] for j in range(Height)]

for h in range(Height):
    a = input()
    
    for w in range(Width):
        if (a[w] == '.'):
            mat[h][w] = 0
        else:
            mat[h][w] = 1

mat = np.array(mat)

h_sur = []
w_sur = []

for h in range(Height):

    if (1 in mat[h]):
        h_sur.append(h)


for w in range(Width):

    if (1 in mat[:, w]):
        w_sur.append(w)


convert_w = len(w_sur)
convert_h = len(h_sur)

convert_mat = [[-1 for i in range(convert_w)] for j in range(convert_h)]
convert_mat=np.array(convert_mat)


for h_index, h in enumerate(h_sur):

    for w_index, w in enumerate (w_sur):

        convert_mat[h_index][w_index] = mat[h][w]


for i in range(convert_h):
    
    s=''
    for j in range(convert_w):
        if (convert_mat[i][j] == 1):
            s += '#'
        else:
            s += '.'
    
    print(s)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[list(input()) for _ in range(H)]

A=[a for a in A if '#' in a]
A=zip(*[a for a in zip(*A) if '#' in a])

for a in A:
    print(''.join(a))

Submission status: Accepted

Solution code:
import numpy as np

n, m = map(int, input().split())
data = []
for _ in range(n):
    d = []
    for s in input():
        if s == '#':
            d.append(1)
        else:
            d.append(0)
    data.append(d)
data = np.array(data)
col = np.sum(data, axis=1)
row = np.sum(data, axis=0)

for i in range(n):
    if col[i] == 0: continue
    for j in range(m):
        if row[j]==0: continue
        s = '#' if data[i][j] == 1 else '.'
        print(s, end='')
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
a=[x for x in a if "#" in x]
a=[x for x in zip(*a) if "#" in x]
a=[list(x) for x in zip(*a)]
for b in a:
  print("".join(b))

Submission status: Accepted

Solution code:
h,w = (int(x) for x in input().split())
ab = []
counth = 0
for _ in range(h):
    a = input()
    a = list(a)
    if '#' not in a:
        counth += 1
        continue
    ab.append(a)
countw =[] 
for i in range(w):
    memo = 0
    #print(12121)
    for j in range(h-counth):
        if ab[j][i] == '.':
            memo += 1
            if memo == h-counth:
                countw.append(i)
countw.sort(reverse=True)
for j in countw:
    for i in range(h-counth):
        del ab[i][j]

for i in range(h-counth):
    print(''.join(ab[i]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]

l=[i for i in l if '#' in i]
l=[list(i) for i in zip(*l)]
l=[i for i in l if '#' in i]
l=[list(i) for i in zip(*l)]

for i in l:
  print(''.join(i))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
S = [list(input()) for i in range(H)]

ans_h = []
for h in range(H) :
    flag = False
    for w in range(W) :
        if S[h][w] == "#" :
            flag = True
    if flag == True :
        ans_h.append(h)

ans_w = []
for w in range(W) :
    flag = False
    for h in range(H) :
        if S[h][w] == "#" :
            flag = True
    if flag == True :
        ans_w.append(w)

for h in ans_h :
    for w in ans_w :
        print(S[h][w], end="")
    print("")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]

tate = []
yoko = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            yoko.append(i)
            tate.append(j)

for i in range(h):
    for j in range(w):
        if i in yoko and j in tate:
            print(a[i][j], end="")
    if i in yoko:
        print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a_li = [input() for i in range(H)]
li = []
for i in range(H) :
    if "#" in a_li[i] :
        li.append(a_li[i])
del_nums = []
for i in range(W) :
    col_li = [row[i] for row in li]
    if not "#" in col_li :
        del_nums.append(i)
for l in li :
    for i in range(W) :
        if not i in del_nums :
            print(l[i],end="")
    print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[input() for _ in range(H)]

del_row="."*W

for i in range(len(a)):
    row=a.pop(0)
    if row!=del_row:
        a.append(row)

del_col="."*len(a)
del_list=[]
for w in range(W):
    string=""
    for h in range(len(a)):
        string+=str(a[h][w])
    if string==del_col:
        del_list.append(w)

ans_list=[]
for h in range(len(a)):
    string=""
    for w in range(W):
        if not w in del_list:
            string+=a[h][w]
    ans_list.append(string)

for i in ans_list:
    print(i)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())

S=[""]*H

for i in range(H):
    S[i]=input()

isWw=[0]*W
isWh=[0]*H

for i in range(H):
    for k in range(W):
        if(S[i][k]=='#'):
            isWw[k]=1
            isWh[i]=1


for i in range(H):
    if(isWh[i]==0):
        continue
    for k in range(W):
        if(isWw[k]==1):
            print(S[i][k],end='')
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
cells = []
for _ in range(H):
    a = list(input())
    try:
        idx = a.index('#')
        cells.append(a)
    except:
        pass
# print('cells', cells)
cells = list(zip(*cells))
# print('cells', cells)
ans = []
for cell in cells:
    try:
        idx = cell.index('#')
        ans.append(cell)
    except:
        pass
ans = list(zip(*ans))
# print('ans', ans)
for i in ans:
    print(''.join(i))

Submission status: Accepted

Solution code:

def main():

    H, W = map(int, input().split())

    mat = []
    for _ in range(H):
        A = input()

        flag = False
        for a in A:
            if a != '.':
                flag = True
        if flag:
            mat.append(A)

    l = []
    for i in range(W):
        flag = True
        for ary in mat:
            if ary[i] != '.':
                flag = False
                break
        if not flag:
            l.append(i)

    for s in mat:
        for i in l:
            print(s[i], end="")
        print()

main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]

a = list(zip(*[i for i in a if "#" in i]))
a = list(zip(*[j for j in a if "#" in j]))

for n in range(len(a)):
    print("".join(a[n]))

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

b = []
c = []
cnt = 0

for i in range(h):
    if set(a[i]) != {'.'}:
        b.append(a[i])
        cnt += 1

b = np.array(b)
b =b[::-1,:].T
b = list(b)

for j in range(w):
    if set(b[j]) != {'.'}:
        c.append(b[j])

c = np.array(c)
c = c[::-1,:].T
c = c[::-1,::-1]
c = list(c)

for i in range(cnt):
    print(''.join(map(str, c[i])))

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    h,w=INTM()
    a=[]
    wd=[]
    for i in range(h):
        temp=STR()
        if temp!='.'*w:
            a.append(temp)
    h=len(a)
    for i in range(w):
        flg=1
        for j in range(h):
            if a[j][i]=='#':
                flg=0
        if flg==1:
            wd.append(i)
    wd=sorted(wd,reverse=True)
    for i in wd:
        for j in range(h):
            #print(i,j)
            a[j]=a[j][:i]+a[j][i+1:]
    for i in range(h):
        print(a[i],sep='')
        
    
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a = [input() for i in range(H)]
b = []
for i in range(H):
  if a[i].count('.')!=W:
    b.append(a[i])

flags=[False]*W

for i in range(H):
  for j in range(W):
    if a[i][j] != '.':
      flags[j]=True

for i in range(len(b)):
  tmp=[]
  for j in range(W):
    if flags[j]:
      tmp.append(b[i][j])
  print(''.join(tmp))

Submission status: Accepted

Solution code:
import math


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


h, w = map(int, input().split())
a = [None]*h
# print(a)
for i in range(h):
    a[i] = input()
# print(a)
x = [None]*h
y = [None]*w
# print(x)
# print(y)
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            x[i] = True
            y[j] = True
# print(x)
# print(y)
for i in range(h):
    if x[i] == True:
        for j in range(w):
            if y[j] == True:
                print(a[i][j], end="")
        print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for _ in range(H):
    t = list(input())
    if t.count('.') != W:
        a.append(t)
    # a.append(list(input()))
# x_white = '.' * W
# i, j = 0, 0
# while True:
#     if a[i] == x_white:
#         a.remove(x_white)
#         j += 1
#     else:
#         i += 1
#     if i == H - j:
#         break
# print(a)
for i in range(W):
    y_white = True
    for j in range(len(a)):
        if a[j][i] == '#':
            y_white = False
    if y_white:
        for j in range(len(a)):
            a[j][i] = ''

for i in range(len(a)):
    answer = ''
    for j in a[i]:
        answer += j
    print(answer)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
yck = [1] * H
xck = [1] * W

for y in range(H):
    for x in range(W):
        if a[y][x] == '#':
            yck[y] = 0
            xck[x] = 0
for y in range(H):
    if yck[y]: continue
    ans = ''
    for x in range(W):
        if xck[x]: continue
        ans += a[y][x]
    print(ans)

Submission status: Accepted

Solution code:
h,w = [int(x) for x in input().split()]
a = []
for _ in range(h):
    tmp = list(input())
    if set(tmp) != set("."):
        a.append(tmp)

for i in range(w):
    save = False
    for y in range(len(a)):
        if a[y][i] == '#':
            save = True
            break
    if not save:
        for y in range(len(a)):
            a[y][i] = '0'

for x in a:
    print(*[z for z in x if z != '0'],sep="")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
al = list(list(input()) for _ in range(h))
row = [False] * w
col = [False] * h

for i in range(h):
    for j in range(w):
        if al[i][j] == '#':
            col[i] = True
            row[j] = True
ans = []
w_len = len(row) - row.count(False)
for i in range(h):
    tmp = ''
    if col[i]:
        for j in range(w):
            if row[j]:
                tmp += al[i][j]
        ans.append(tmp)

for a in ans:
    print(*a, sep='')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
al = list(list(input()) for _ in range(h))
row = [0]*w
col = [0]*h

for i in range(h):
    for j in range(w):
        if al[i][j] == '#':
            col[i] += 1
            row[j] += 1
ans = []
w_len = len(row) - row.count(0)
for i in range(h):
    tmp = ''
    if col[i] != 0:
        for j in range(w):
            if row[j] != 0:
                tmp += al[i][j]
        ans.append(tmp)

for a in ans:
    print(*a, sep='')

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int, input().split())
al = list(list(input()) for _ in range(h))
al_n = np.array(al)
row = [0]*w
col = [0]*h
for i in range(h):
    for j in range(w):
        if al_n[i][j] == '.':
            row[j] += 1
            col[i] += 1
row_ = []
col_ = []
for i in range(w):
    if row[i] == h:
        row_.append(i)

for j in range(h):
    if col[j] == w:
        col_.append(j)

if len(col_) > 0:
    al_n = np.delete(al_n, col_, axis=0)

if len(row_) > 0:
    al_n = np.delete(al_n, row_, axis=1)

for a in al_n:
    print(*a, sep='')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
data=[]
count_x=[0]*w
count_y=[0]*h
for i in range(h):
    a_i=input()
    for j in range(w):
        if a_i[j]=="#":
            count_y[i]+=1
            count_x[j]+=1
    data.append(a_i)
for i in range(h):
    if count_y[i]!=0:
        data_i=data[i]
        ans=""
        for j in range(w):
            if count_x[j]!=0:
                ans+=data_i[j]
        print(ans)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
lsa=[]
#lsacom=[]
dcomi={}
dcomj={}
for i in range(H):
    lsa.append(input())
for i in range(H):
    for j in range(W):
        if lsa[i][j]=="#":
            break
    else:
        dcomi[i]=1
for j in range(W):
    for i in range(H):
        if lsa[i][j]=="#":
            break
    else:
        dcomj[j]=1
for i in range(H):
    for j in range(W):
        if (not i in dcomi) and (not j in dcomj):
            print(lsa[i][j],end="")
    if not i+1 in dcomi:
        print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[0 for _ in range(h)] for _ in range(w)]
ans=[]
#print(a)
for i in range(h):
    b=list(input())#w nonagasa 
    if '#'  in b:
        for j in range(w):
            a[j][i]=b[j]
#for i in range(w):
    #print(a[i])
c=0
for i in range(0-c,w-c):
    if '#' not in a[i]:
        for j in range(h):
            a[i][j]=0
for i in range(h):
    for j in range(w):
        if a[j][i]!=0:
            print(a[j][i],end="")
            c+=1
    if c!=0:
        print()
    c=0

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
L=[]
d=set(".")
for i in range(n):
  s=input()
  if set(list(s))!=d:
    L.append(list(s))
l=[list(a) for a in  zip(*L) if set(a)!=set(".")]
for a in zip(*l):
  print("".join(a))

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
nsl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

H, W = na()
m = nsl(H)

for i in range(W):
    flag = True
    for j in range(H):
        if m[j][i] != '.':
            flag = False
    if flag:
        for j in range(H):
            m[j][i] = '$'

for i in range(H):
    flag = True
    for j in range(W):
        if m[i][j] != '.' and m[i][j] != '$':
            flag = False
    if flag:
        for j in range(W):
            m[i][j] = '$'

o = [[] for i in range(H)]
for i in range(H):
    for j in range(W):
        if m[i][j] != '$':
            o[i].append(m[i][j])

for i in o:
    if len(i) >= 1:
        for j in i:
            print(j, end="")
        print()

Submission status: Accepted

Solution code:
#107_B
H,W=map(int,input().split())
A=[]
for _ in range(H):
    S=input()
    if set(S)=={'.'}:
        continue
    A.append(list(S))
for w in range(W-1,-1,-1):
    flg=True
    for h in range(len(A)):
        if A[h][w]=='#':
            flg=False
    if flg:
        for h in range(len(A)):
            A[h].pop(w)

for s in A:
    print(''.join(s))

Submission status: Accepted

Solution code:
import numpy
h,w = map(int, input().split())
l = list()
for i in range(h):
    l.append(list(input()))
l = numpy.array(l)
kari = 0
kari2 = []
for i in range(h):
    for j in range(w):
        if l[i][j] == ".":
            kari += 1
    if kari == w:
        kari2.append(i)
    kari = 0
kari2 = kari2[::-1]
h -= len(kari2)
for i in kari2:
    l = numpy.delete(l, i, 0)
kari2 = []
for i in range(w):
    for j in range(h):
        if l[j][i] == ".":
            kari += 1
    if kari == h:
        kari2.append(i)
    kari = 0
kari2 = kari2[::-1]
for i in kari2:
    l = numpy.delete(l, i, 1)
l = l.tolist()
for i in range(h):
    print(*l[i],sep="")

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
f = np.array([list(input()) for _ in range(h)])

f = f[~np.all(f=='.', axis=1), :]
f = f[:, ~np.all(f=='.', axis=0)]

print('\n'.join(''.join(row) for row in f))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())

a = [['x'] * w for i in range(h)]
for i in range(h):
    tmp = list(str(input()))
    for j in range(w):
        a[i][j] = tmp[j]


for i in range(h):
    flag = True
    for j in range(w):
        if a[i][j] == '#':
            flag = False

    if flag:
        for j in range(w):
            a[i][j] = 'x'

arr = []
for i in range(h):
    if a[i][0] == 'x':
        pass
    else:
        arr.append(a[i])


s = [len(v) for v in arr]
h = len(s)
w = s[0]

for i in range(w):
    flag = True
    for j in range(h):
        if arr[j][i] == '#':
            flag = False

    if flag:
        for j in range(h):
            arr[j][i] = 'x'

for i in range(h):
    for j in range(w):
        if arr[i][j] != 'x':
            print(arr[i][j], end='')
    print('')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]

for i in range(h-1,-1,-1):
    if set(a[i]) == {'.'}:
        del a[i]

for j in range(w-1,-1,-1):
    cnt = 0
    for k in range(len(a)):
        if a[k][j] == '.':
            cnt += 1
    if cnt == len(a):
        for l in range(len(a)):
            del a[l][j]
for i in a:
    print("".join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
mass = [input() for _ in range(h)]
for i in reversed(range(h)):
    if mass[i].count("#") == 0:
        mass = mass[:i] + mass[i+1:]

for i in reversed(range(w)):
    cnt = 0
    for row in mass:
        if row[i] == "#":
            cnt += 1
    if cnt == 0:
        for j, row in enumerate(mass):
            mass[j] = row[:i] + row[i+1:]

print("\n".join(mass))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = []
row = []
for i in range(H):
    tmp = list(input())
    if tmp.count(".") == len(tmp):
        row.append(i)
    a.append(tmp)
column = []
for i in range(W):
    count = 0
    for j in range(H):
        if a[j][i] == ".":
            count += 1
    if count == H:
        column.append(i)

for i in range(H):
    if i not in row:
        for j in range(W):
            if j not in column:
                print(a[i][j],end="")
        print("")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a=[]
for i in range(H):
    x = input()
    if "#" in x:
        a.append(list(x))
b=[i for i in zip(*a)]
c=[]
for i in range(W):
    if "#" in b[i]:
        c.append(b[i])
c=[i for i in zip(*c)]
for i in c:
    print(*i, sep="")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=['']*h
for i in range(h):
    a[i]=input()
r=[0]*h
c=[0]*w

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            r[i]=1
            c[j]=1
for i in range(h):
    if r[i]:
        for j in range(w):
            if c[j]:
                print(a[i][j],end='')
        print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]

ans = [ch for ch in a if "#" in ch]
ans = [ch for ch in zip(*ans) if "#" in ch]
ans = [ch for ch in zip(*ans)]

for i in range(len(ans)):
    print(''.join(ans[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
table = []
for i in range(h):
    tmp = input()
    if tmp != '.' * w:
        table.append(tmp)
ans = []
for s in zip(*table):  # 転置
    if '#' in s:
        ans.append(s)
for a in zip(*ans):  # 転置し直す
    print(''.join(a))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
#a=[[j for j in input()] for i in range(h)]

lis=[]
for i in range(h):
#     a=list(map(str,input().split()))
    a = list(input())
    if '#' in a:
        lis.append(a)
lis2=list(zip(*lis))
lis_ans=[]
for i in range(w):
    if '#' in lis2[i]:
        lis_ans.append(lis2[i])
lis_ans = list(zip(*lis_ans))
# print(list(zip(*lis_ans)))
# print(lis_ans)
for i in range(len(lis_ans)):
    print(''.join(lis_ans[i]))

Submission status: Accepted

Solution code:
h, w = (int(x) for x in input().split())
a = [[0 if x == "." else 1 for x in input()] for _ in range(h)]
l = []
for i in range(h):
    if sum(a[i][:]) == 0: l.append(i)
if len(l) != 0:
    l = l[::-1]
    for l_i in l:
        a.pop(l_i)
l = []
for i in range(w):
    s = 0
    for j in range(len(a)):
        s += a[j][i]
    if s == 0: l.append(i)
if len(l) != 0:
    l = l[::-1]
    for l_i in l:
        for i in range(len(a)):
            a[i].pop(l_i)
ans = [["#" if int(x) == 1 else "." for x in a[i]] for i in range(len(a))]
for ans_i in ans:
    print("".join(ans_i))

Submission status: Accepted

Solution code:
def examA():
    N, i = LI()
    ans = N - i + 1
    print(ans)
    return

def examB():
    H, W = LI()
    A = [SI() for _ in range(H)]
    h = [[]for _ in range(H)]
    for i in range(W):
        flag = False
        for j in range(H):
            if A[j][i]=="#":
                flag = True
                break
        if flag:
            for j in range(H):
                h[j].append(A[j][i])
    #print(h)
    ans = []
    for i,a in enumerate(h):
        if "#" in a:
            ans.append(i)
    for v in ans:
        print("".join(map(str,h[v])))
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
l = []
for i in range(h):
  a = str(input())
  if a == '.'*w:
    continue
  l.append(a)

skip = []
for i in range(w):
  for j in range(len(l)):
    if l[j][i] == '#':
      break
  else:
    skip.append(i)

skip = set(skip)
l_ = [0]*len(l)
for i in range(len(l)):
  temp = ''
  for j in range(w):
    if j not in skip:
      temp += l[i][j]
  l_[i] = temp
  
for i in range(len(l_)):
  print(l_[i])

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
ban = []
banban = []

for i in range(h):
  tmp = input()
  if tmp != '.'*w:
    ban.append(list(tmp))

for zlist in zip(*ban):
  if '#' in zlist:
    banban.append(zlist)

for letter in zip(*banban):
  print(''.join(letter))

Submission status: Accepted

Solution code:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    H, W = read_values()
    F = [input() for _ in range(H)]

    T = [False] * W
    for f in F:
        if f.count("#") == 0:
            continue
        
        for w, s in enumerate(f):
            if s == "#":
                T[w] = True

    for f in F:
        if f.count("#") == 0:
            continue
        print("".join([s for i, s in enumerate(f) if T[i]]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = ['']*h
for i in range(h):
    A[i] = input()

r = [False]*h
c = [False]*w
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            r[i] = True
            c[j] = True

for i in range(h):
    if r[i]:
        for j in range(w):
            if c[j]:
                print(A[i][j], end='')
        print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for j in range(h)]

for p in range(w):
    f=True
    for q in range(h):
        if a[q][p]=="#":f=False
    if f:
        for y in range(h):a[y][p]=""
res=[]
for t in a:
    if t.count(".")+t.count("")!=len(t):res.append(t)
for t in res:
    print("".join(t))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np


def main():
    H, W = map(int, input().split())
    # A = [list(input()) for _ in range(H)]
    A = np.array([list(input()) for _ in range(H)])
    A = A[:, ~np.all(A == '.', axis=0)]
    A = A[~np.all(A == '.', axis=1), :]
    [print(''.join(A[i, :])) for i in range(np.shape(A)[0])]


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = list(zip(*[i for i in a if "#" in i]))
a = list(zip(*[i for i in a if "#" in i]))
for i in range(len(a)):
    print("".join(a[i]))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = []
yoko = [False]*h
tate = [False]*w
for i in range(h):
    a.append(list(str(input())))

for x in range(h):
    for y in range(w):
        if a[x][y] == '#':
            yoko[x] = True
            tate[y] = True

for x in range(h):
    if yoko[x]:
        for y in range(w):
            if tate[y]:
                print(a[x][y], end="")
        else:
            print("")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A=[""]*H
for i in range (H):
	A[i]=input()

V=[0]*H
X=[0]*W
for i in range (H):
	for j in range (W):
		if A[i][j]=="#":
			V[i]=1
			X[j]=1

for i in range (H):
	if V[i]==1:
		for j in range (W):
			if X[j]==1:
				print(A[i][j],end="")
		print()

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a = np.array([list(input()) for _ in range(H)])

# 行
del_index_0 = []
for i in range(H):
    if np.all(a[i]==['.']*W):
        del_index_0.append(i)
b = np.delete(a, del_index_0, axis=0)

# 列
del_index_1 = []
for i in range(W):
    if np.all(b[:,i]==['.']*(H-len(del_index_0))):
        del_index_1.append(i)
c = np.delete(b, del_index_1, axis=1)

for i in c:
    print(''.join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
slist=[input() for i in range(h)]
c=1
while c==1:
  c=0
  for i in range(h):
    s=slist[i]
    if "#" not in s:
      del slist[i]
      h -= 1
      c=1
      break
  if c==0:
    for i in range(w):
      li = [slist[j][i] for j in range(h)]
      if len(set(li))==1 and "." in li:
        for j in range(h):
          slist[j]=slist[j][:i]+slist[j][i+1:]
        c=1
        w -=1
        break
for i in range(h):
  print(slist[i])