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):
    b = input()
    if "#" in b:
        a.append(b)
field = []
for j in range(W):
    c = ''
    for k in range(len(a)):
        c += a[k][j]
    if "#" in c:
        field.append(c)

length = len(field[0])
result = []
for k in range(length):
    newfield = ''
    for l in range(len(field)):
        newfield += field[l][k]
    print(newfield)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
M = []
for i in range(H):
    L = list(input())
    if '#' in L:
        M.append(L)
Mt = list(map(list, zip(*M)))
A = []
for i in range(W):
    L = Mt[i]
    if '#' in L:
        A.append(L)
ans = list(map(list, zip(*A)))
for i in range(len(ans)):
    L = ans[i]
    print("".join(L))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
aij = []

for i in range(H):
    aij.append( list(input()) )

# print(aij)

ans = []
for i in range(H):
    if aij[i] == ['.']*W:
        continue
    else:
        ans.append(aij[i])

pop_num = []
for j in range(W):
    tmp = []
    for i in range(len(ans)):
        tmp.append(ans[i][j])
    if tmp == ['.']*len(ans):
        for i in range(len(ans)):
            pop_num.append(j)

ans2 = []
for i in range(len(ans)):
    tmp = []
    for j in range(W):
        if j not in pop_num:
            tmp.append(ans[i][j])
    ans2.append(tmp)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
h,w=map(int,input().split())
l=["" for i in range(w)]
yo=[]
for i in range(h):
    s=input()
    for a,j in enumerate(s):
        l[a]+=j
for i in l:
    if "#" in i:
        yo.append(i)
x=len(yo[0])
ans=["" for i in range(x)]
for i in yo:
    for a,j in enumerate(i):
        ans[a]+=j
for i in ans:
    if "#" in i: print(i)

Submission status: Accepted

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

rm = []

for i in range(H):
    if "#" not in a[i]:
        for j in range(W):
            rm.append([i,j])

for i in range(W):
    t = []
    for k in range(H):
        t.append(a[k][i])
    if "#" not in t:
        for j in range(H):
            rm.append([j,i])


aa = []
for i in range(H):
    t = []
    for j in range(W):
        if [i,j] not in rm:
            t.append(a[i][j])
    if len(t) != 0 :
        aa.append(t)


for i in range(len(aa)):
    for j in range(len(aa[i])):
        print(aa[i][j],end="")
    print("")

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
map = [[str(i) for i in input()] for j in range(H)]
delList1 = []
delList2 = []
for k in range(H):
    if "#" not in map[k]:
        delList1.append(k)

for l in reversed(delList1):
    del map[l]

for m in range(W):
    if "#" not in [n[m] for n in map]:
        delList2.append(m)

for o in reversed(delList2):
    for p in range(len(map)):
        map[p].pop(o)

for q in map:
    print("".join(q))

Submission status: Accepted

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

while True:
    for i in range(0, h):
        if all([a[i][j]=='.' for j in range(0, w)]):
            del a[i]
            h -= 1
            break
    else:
        for j in range(0, w):
            if all([a[i][j]=='.' for i in range(0, h)]):
                for i in range(0, h):
                    a[i] = a[i][:j] + a[i][j+1:]
                w -= 1
                break
        else:
            for k in range(0, h):
                print(a[k])
            exit()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
def trans(x):
    if x == '.':
        return False
    else:
        return True
a = []
for i in range(H):
    v = input()
    if v == '.'*W:
        H -= 1
    else:
        a.append(v)
test = [True for j in range(W)]
d = 0
for i in range(H):
    test = [True if test[j] and a[i][j] == '.' else False for j in range(W)]
for j in range(W):
    if test[j]:
        a = [a[i][:(j-d)]+a[i][(j-d+1):] for i in range(H)]
        d += 1
for i in range(H):
    print(a[i])

Submission status: Accepted

Solution code:
tateN, YokoN = map(int,input().split())
arr = [input() for i in range(tateN)]

#縦を検索
tateline = list()
for i in range(0, tateN):
    if arr[i].find('#') != -1:
        tateline.append(i)

yokoline = list()
for j in range(0, YokoN):
    found = False
    for tate in range(0, tateN):
        if arr[tate][j] == '#': found = True
    if found : yokoline.append(j)

for t in tateline:
    prstr = ''
    for y in yokoline:
        prstr += arr[t][y]
    print(prstr)

Submission status: Accepted

Solution code:

h,w = map(int,input().split())
li = []
del_r = []
del_c = []
for i in range(h):
    li.append(list(input()))
    #print(i)
    
    for j in range(w):
        if li[i][j] == '#':
            break
            
        if li[i][j] == '.' and j == w-1:
            del_r.append(int(i))

for j in range(w):
    for i in range(h):
        if li[i][j] == '#':
            break
        if li[i][j] == '.' and i == h-1:
            del_c.append(int(j))
            
#print(del_r)
#print(del_c)

for i in range(h):
    if i in del_r:
        continue
    for j in range(w):
        if j in del_c:
            continue
        print(li[i][j], end="")
    print("")

Submission status: Accepted

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

hlist = []
for i in range(0,h):
    for j in range(1,w):
        if a[i][j-1] !=  a[i][j]:
            break
        if j == w-1 and a[i][j] == ".":
            hlist.append(i)
wlist = []
for j in range(0,w):
    for i in range(1,h):
        if a[i-1][j] !=  a[i][j]:
            break
        if i == h-1 and a[i][j] == ".":
            wlist.append(j)

b = 0
for i in hlist:
    a.pop(i-b)
    b += 1
    h -= 1
b = 0
for j in wlist:
    for i in range(0,h):
        a[i].pop(j-b)
    b += 1
    w -= 1

for i in range(0,h):
    for j in range(0,w):
        if j < w-1:
            print(a[i][j],end="")
        else:
            print(a[i][j])

Submission status: Accepted

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

a = []

for i in range(h):
	b = input()
	if b.count('.') != m:
		a.append(b)

b = len(a)
c =['' for i in range(m)]

for i in a:
	for j in range(m):
		c[j] += i[j]
d = []
for i in c:
	if i.count('.') != len(i):
		d.append(i)

b = len(d)
c =['' for i in range(len(d[0]))]

for i in d:
	for j in range(len(d[0])):
		c[j] += i[j]

for i in c:
	print(i)

Submission status: Accepted

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

for i in range(0, H):
    temp = list(input())
    grid.append(temp)

yoko = []
tate = []
for i in range(0, H):
    judge = True
    for j in range(0, W):
        if grid[i][j] != '.':
            judge = False
    if judge:
        yoko.append(i)
        
for i in range(0, W):
    judge = True
    for j in range(0, H):
        if grid[j][i] != '.':
            judge = False
    if judge:
        tate.append(i)


for i in range(0, H):
    for j in range(0, W):
        if i in yoko or j in tate:
            pass
        else:
            print(grid[i][j], end='')
    if not i in yoko:
        print('')

Submission status: Accepted

Solution code:
# coding: utf-8

h, w = [int(i) for i in input().split()]

a = [list(input()) for _ in range(h)]

for i in range(h - 1, -1, -1):
    if all([x == "." for x in a[i]]):
        del(a[i])

for j in range(w - 1, -1, -1):
    flg = True
    for i in range(len(a)):
        if a[i][j] == "#":
            flg = False
            break

    if flg:
        for i in range(len(a)):
            del(a[i][j])

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

Submission status: Accepted

Solution code:
import sys
sdin = sys.stdin.readline

h,w = map(int, sdin().split())
field = []
for hi in range(h):
    field.append(sdin())
    
f2 = []
for hi in range(h):
    if field[hi].count("#") > 0:
        f2.append(field[hi])
    
f2_char = [list(f2[hi]) for hi in range(len(f2))]

# 列を圧縮
has_black_list = []
for wj in range(w):
    has_black = False
    for hi in range(len(f2)):
        if f2_char[hi][wj] == "#":
            has_black = True    
    
    if has_black:
        has_black_list.append(wj)
        
field_ans = [["" for wj in range(len(has_black_list))] for hi in range(len(f2))]
for j, wj in enumerate(has_black_list):
    for hi in range(len(f2)):
        field_ans[hi][j] = f2_char[hi][wj]
    

for hi in range(len(f2)):
    print("".join(field_ans[hi]))

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    g = [list(input()) for i in range(h)]

    r = []
    for i in range(h):
        if "#" not in g[i]:
            r.append(i)

    cnt = 0
    for i in r:
        g.pop(i-cnt)
        cnt += 1

    c = []
    for i in range(w):
        for j in range(h-len(r)):
            if g[j][i] == "#":
                break
        else:
            c.append(i)

    for i in range(h-len(r)):
        cnt = 0
        for j in c:
            g[i].pop(j-cnt)
            cnt += 1

    for i in range(h-len(r)):
        print("".join(g[i]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

H,W = map(int, input().split())
HW = []
for i in range(H):
    instr = input()
    if instr.find('#') != -1:
        HW.append(list(instr))
    else:
        H -= 1

# 行列の入れ替え
HW2 = []
for x in zip(*HW):
    HW2.append(x)

HW3 = []
for i in range(W):
    instr = ''.join(HW2[i])
    if instr.find('#') != -1:
        HW3.append(HW2[i])

# もう1回入れ替えて戻す
HW4 = []
for x in zip(*HW3):
    HW4.append(x)

for i in range(H):
    print(''.join(HW4[i]))

Submission status: Accepted

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

a2_list = []
for a in a_list:
    if a.count(".") == W:
        continue
    else:
        a2_list.append(a)
a3_list = []
for j in range(W):
    row = "".join([r[j] for r in a2_list])
    if row.count(".") == len(a2_list):
        continue
    else:
        a3_list.append(row)

for i in range(len(a3_list[0])):
    row = [r[i] for r in a3_list]
    print("".join(row))

Submission status: Accepted

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

l1 = [x for x in l if x != '.'*W]

l2 = [''.join(x) for x in zip(*l1)]

l3 = [x for x in l2 if any([y if y != '.' else False for y in x])]

print("\n".join([''.join(x) for x in zip(*l3)]))

Submission status: Accepted

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

i = 0
while i < H:
    if '#' not in table[i]:
        del table[i]
        H -= 1
    else:
        i = i + 1

table_t = [list(x) for x in zip(*table)]

i = 0
while i < W:
    if '#' not in table_t[i]:
        del table_t[i]
        W -= 1
    else:
        i = i + 1

table = [list(x) for x in zip(*table_t)]

for i in range(H):
    print("".join(table[i]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

line = input().split()
h = int(line[0])
w = int(line[1])

a = []
hr = []
for hi in range(h):
    line = list(input())
    if len(set(line))==1 and line[0]==".":
        hr.append(hi)
    a.append(line)


wr = []
wi = 0
for line in zip(*a):
    if len(set(line))==1 and line[0]==".":
        wr.append(wi)
    wi += 1

for hi in range(h):
    if hi in hr:
        continue
    for wi in range(w):
        if wi not in wr:
            print(a[hi][wi], end="")
    print("")

Submission status: Accepted

Solution code:
import numpy as np

inputs = raw_input().replace("\n", "")
H, W = map(int, inputs.split(" "))

lines = np.asarray([list(raw_input().replace("\n", "")) for h in xrange(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print "".join(outline)

Submission status: Accepted

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

a = []

for _ in range(H):
    a.append(input())

# horizon
h_remove_index = []
for h_i in range(H):
    if not "#" in a[h_i]:
        h_remove_index.append(h_i)




#vertex
v_remove_index = []
for v_i in range(W):
    is_ok = True
    for h_i in range(len(a)):
        if a[h_i][v_i] == "#":
            is_ok = False
            break
    # remove
    if is_ok:
        v_remove_index.append(v_i)
    

for h_i in range(H):
    if h_i in h_remove_index:
        continue
    for v_i in range(W):
        if v_i in v_remove_index:
            continue

        print(a[h_i][v_i], end='')
    print("\n",end='')

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
t=[]
for _ in[0]*H:
    x=input()
    if x!='.'*W:
        t+=[x]
num=len(t)
k=[]
for s in zip(*t):
    s=''.join(s)
    if s!='.'*num:
        k+=[s]
for x in zip(*k[::-1]):
    print(''.join(x[::-1]))

Submission status: Accepted

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

a = np.empty((h, w), dtype=np.str)
for i in range(0, h):
    a[i] = list(input())


height = h
i = 0
while True:
    if i == height:
        break
    if not '#' in a[i]:
        a = np.delete(a, i, axis=0)
        height -= 1
    else:
        i += 1

width = w
i = 0
while True:
    if i == width:
        break
    if not '#' in a[:, i]:
        a = np.delete(a, i, axis=1)
        width -= 1
    else:
        i += 1

for i in range(0, len(a)):
    print(''.join(a[i]))

Submission status: Accepted

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

M = list( input() for _ in range(H) )
A=[]
C=[]
r=0
c=W

#print(M)

for i in range(H):
	m = M[i]
	if "#" in m:
		A.append(m)
		r+=1

#print(r,c)
#print(A)

for j in range(c):
	for i in range(r):
		a = A[i][j]
		if a=='#': break
	else:
		C.append(j)

#print(C)

for r in A:
#	print(r)
	for c in range(len(r)):
		if not (c in C):
			print(r[c], end='')
	print('')

Submission status: Accepted

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

matrix = []

for i in range(h):
  row = list(input())
  if '#' not in row:
    continue
  else:
    matrix.append(row)

removed_index = []

for i in range(len(matrix[0])):
  col = [row[i] for row in matrix]
  if '#' not in col:
    removed_index.append(i)

removed_index.reverse()

for n in removed_index:
  for row in matrix:
  	del row[n]

for row in matrix:
  print(''.join(row))

Submission status: Accepted

Solution code:
a,b=map(int, input().split(" "))
arr=[]
for i in range(a):
    line=list(input())
    #for j in line;
    arr.append(line)
    #for j in range(b)
    #    arr.append()
    #line=input()
    #if "#" in line:
    #    arr.append(line)

out=[]
for i in arr:
    if "#" in i:
        out.append(i)

count={}
for i in range(len(out)):
    for j in range(len(out[0])):
        if j not in count:
            count[j]=0
        if out[i][j]=="#":
            count[j]+=1
#print(count)
#print(arr)
#print(out)

for line in out:
    result=""
    for num,i in enumerate(line):
        if count[num]!=0:
            result+=i

    if result != "":
        print(result)

Submission status: Accepted

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

a = [i for i in range(h)]
for i in range(h):
    if string[i] == "."*w:
        a.remove(i)

stringT = [[string[j][i] for j in range(h)] for i in range(w)]

b = [i for i in range(w)]

for i in range(w):
    if "".join(stringT[i]) == "."*h:
        b.remove(i)

st = [[string[i][j] for j in b] for i in a]
for i in range(len(st)):
    print("".join(st[i]))

Submission status: Accepted

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

list1=[]
for i in range(H):
    a=input()
    if a.count(".")==len(a):
        pass
    else:
        list2=[]
        for m in range(len(a)):
            
            list2.append(a[m])
        list1.append(list2)
        list2=[]
#print(list1[0][3])
list3=[]
for j in range(W):
    count=0
    if list1[0][j]==".":
        for k in range(len(list1)):
            if list1[k][j]==".":
                count+=1
        if count==len(list1):
            list3.append(j)
            
#print(list3)

list4=[]
for x in range(len(list1)):
    list5=[]
    for y in range(W):
        if y in list3:
            pass
        else:
            list5.append(list1[x][y])
    list4.append(list5)
    list5=[]
#print(list4)

for c in range(len(list4)):
    print("".join(list4[c]))

Submission status: Accepted

Solution code:
inputs = input().strip().split()

H = int(inputs[0])
W = int(inputs[1])

a = []

for i in range(H):
    inputs = input()
    a.append(inputs)

for i in range(W):
    flag = True
    for j in range(H):
        if a[j][i] == "#":
            flag = False
    if flag:
        for j in range(H):
            a[j] = a[j][:i] + '*' + a[j][i+1:]

for i in range(H):
    if a[i].find("#") < 0:
        a[i] = ''

for i in range(H):
    if a[i] != '':
        print(a[i].replace('*', ''))

Submission status: Accepted

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

b = []
for y in range(len(a)):
    for x in range(len(a[y])):
        if a[y][x] != '.':
            b.append(a[y])
            break

c = ['' for _ in range(len(b))]
for x in range(len(b[0])):
    for y in range(len(b)):
        if b[y][x] != '.':
            for y in range(len(b)):
                c[y] += b[y][x]
            break

print('\n'.join(c))

Submission status: Accepted

Solution code:
import numpy as np

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

ans = []
for i in range(H):
  ans.append(input())
  
ind = []
k = len(ans)
for i, ss in enumerate(reversed(ans)):
  if ss == "." * W:
    ind.append(k-i-1)
  
index = []
for i in range(H):
  for j in range(W):
    if ans[i][j] == "#":
      index.append(j)

for i in range(H):
  if i in ind:
    continue
  aaa = ""
  for j in range(W):
    if j in index:
      aaa += ans[i][j]
      
  print(aaa)

Submission status: Accepted

Solution code:
H,W = [int(i) for i in input().split()]
A = [input() for _ in range(H)]
B = []
for i in range(H-1,-1,-1):
    if not "#" in A[i]:
        del A[i]
for i in range(W):
    flag = True
    for j in range(len(A)):
        if A[j][i] == "#":
            flag = False
    if flag:
        B.append(0)
    else:
        B.append(1)
for i in A:
    tmp = ""
    for j in range(len(i)):
        if B[j]:
            tmp+=i[j]
    print(tmp)

Submission status: Accepted

Solution code:
inp = list(map(int, input().split()))
H, W = inp[0], inp[1]

import numpy as np

arr = np.array([[0 if e == '.' else 1 for e in input().split()[0]] for _ in range(H)])

h = []
for i in range(H):
    if (arr[i] == [0] * W).all():
        h.append(i)
ind = np.ones(H, dtype=bool)
ind[h] = False
arr = arr[ind]

w = []
for i in range(len(arr[0])):
    if (arr[:, i] == [0] * len(arr[:,0])).all():
        w.append(i)
ind = np.ones(len(arr[0]), dtype=bool)
ind[w] = False
arr = arr[:, ind]

for i in range(len(arr)):
    txt = ''
    for j in range(len(arr[0])):
        if arr[i][j] == 0:
            txt += '.'
        else:
            txt += '#'
    print(txt)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
v = ['' for i in range(a)]
for i in range(a):
    v[i] = input()
for i in range(a):
    k = a - i - 1
    x = 0
    for j in range(b):
        if v[k][j] == '#':
            x = 1
    if x == 0:
        v.pop(k)



for i in range(b):
    k = b - i - 1
    x = 0
    for j in range(len(v)):
        if v[j][k] == '#':
            x = 1
    if x == 0:
        for j in range(len(v)):
            v[j] = v[j][:k] + v[j][k+1:]
            
for i in v:
    print(i)

Submission status: Accepted

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

D = []
f = [0] * W
for i in range(H):
    d = input()
    if d.count('.') == W:
        continue
    D.append(d)
    for j in range(W):
        if d[j] == '.':
            f[j] += 1

re = [''] * len(D)
for i in range(len(D)):
    str = D[i]
    for j in range(len(str)):
        if f[j] != len(D):
            re[i] += str[j]

for str in re:
    print(str)

Submission status: Accepted

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

grid = []
dot_h = []
sharp_h = []
dot_w = []
sharp_w = []

for h in range(H):
    line = input()
    line = line[:W]
    grid.append(line)
    if line.count('.') == W:
        dot_h.append(h)
    # if line.count('#') == W:
    #     sharp_h.append(h)
for w in range(W):
    dot_c = 0
    sharp_c = 0
    for h in range(H):
        if grid[h][w] == '.':
            dot_c += 1
        # if grid[h][w] == '#':
        #     sharp_c += 1
    if dot_c == H:
        dot_w.append(w)
    if sharp_c == H:
        sharp_w.append(w)
    
for h in range(H):
    if h in dot_h or h in sharp_h:
        continue
    for w in range(W):
        if w in dot_w or w in sharp_w:
            continue
        # print(grid[h][w], end="")
        sys.stdout.write(grid[h][w])
    print('')

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    a = []
    for _ in range(H):
        a.append(input())
    h = []
    w = []
    for i in range(H):
        if a[i] == "."*W:
            h.append(i)
    for i in range(W):
        b = ""
        for j in range(H):
            b += a[j][i]
        if b == "."*H:
            w.append(i)
    
    for i in range(H):
        out = ""
        for j in range(W):
            if (i in h) or (j in w):
                out += ""
            else:
                out += a[i][j]
        if out != "":
            print(out)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

def main():
    h, w = map(int,input().split())
    arr = [0 for i in range(h)]

    for i in range(h):
        arr[i] = list(input())

    arr = np.array(arr)
    yoko = []
    tate = []

    for i in range(h):
        if np.any(arr[i]=='#') == False:
            yoko.append(i)

    for i in range(w):
        if np.any(arr.transpose()[i]=="#") == False:
            tate.append(i)

    arr = np.delete(arr, yoko, 0)
    arr = np.delete(arr, tate, 1)

    for i in arr:
        print("".join(i))



if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
import numpy as np

line = input().split()
H = int(line[0])
W = int(line[1])

array = np.ndarray((H, W), np.uint8)

for i in range(H):
    line = input()
    for j in range(W):
        if line[j] == '.':
            array[i, j] = 0
        elif line[j] == '#':
            array[i, j] = 1

W_condition = np.sum(array, axis=0)!=0
H_condition = np.sum(array, axis=1)!=0

array = array[H_condition, :]
array = array[:, W_condition]

h, w = array.shape

for i in range(h):
    line = ''
    for j in range(w):
        if array[i, j] == 0:
            line += '.'
        elif array[i, j] == 1:
            line += '#'
    print(line)

Submission status: Accepted

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

for _ in range(H):
  s = input()
  if '#' in s:
    arr.append(s)

j = 0
while len(arr[0]) > j:
  if '#' not in [arr[i][j] for i in range(len(arr))]:
    for i in range(len(arr)):
      arr[i] = arr[i][:j] + arr[i][(j+1):]
  else:
    j += 1

for s in arr:
  print(s)

Submission status: Accepted

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

while ["."]*W in a:
    a.remove(["."]*W)
    H -= 1

a_t = [list(x) for x in zip(*a)]

while ["."]*H in a_t:
    a_t.remove(["."]*H)

a = [list(x) for x in zip(*a_t)]
a_ = [''.join(x) for x in a]
[print(x) for x in a_]

Submission status: Accepted

Solution code:
def run(h, w, a):
    ret1 = []
    for i in range(h):
        if a[i] != '.'*w:
            ret1.append(a[i])
    wi = []
    for i in range(len(ret1[0])):
        for j in range(len(ret1)):
            if ret1[j][i] == '#':
                wi.append(i)
                break
    ret = []
    for i in range(len(ret1)):
        s = ''
        for j in wi:
            s += ret1[i][j]
        ret.append(s)
    return ret


def read_line():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())
    return (h, w, a)


def main():
    h, w, a = read_line()
    ret = run(h, w, a)
    for i in range(len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
grid = []
for i in range(H):
    row = list(input())
    grid.append(row)
while True:
    r_change = False
    for q in range(len(grid)):
        if "#" not in grid[q]:
            del grid[q]
            r_change = True
            break
    if not r_change:
        break
while True:
    c_change = False
    for k in range(len(grid[0])):
        if "#" not in [row[k] for row in grid]:
            grid = [[row[p] for p in range(len(row)) if p != k] for row in grid]
            c_change = True
            break
    if not c_change:
        break
for row in grid:
    print("".join(row))

Submission status: Accepted

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

BW=[]
for i in range(H):
  nextline=list(input())
  for j in range(W):
    if nextline[j]=='#':
      BW.append(nextline)
      break;

columnWlist=[1]*(W)
for i in range(len(BW)):
  for j in range(W):
    if columnWlist[j]==1 and BW[i][j]=='#':
      columnWlist[j]=0

for i in range(len(BW)):
  for j in range(W-1,-1,-1):
    if columnWlist[j]==1:
      BW[i].pop(j)
      
for i in range(len(BW)):
  for j in range(len(BW[0])):
    print(BW[i][j],end='')
  print()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
s=[]
dels=[]
for i in range(a):
    s.append(input())
for i in range(len(s)):
    f=1
    for j in range(b):
        if s[i][j]!='.':
            f=0
            break
    if f:
        dels.append(i)
k=0
for i in dels:
    del s[i-k]
    k=k+1
dels=[]
for i in range(b):
    f=1
    for j in range(len(s)):
        if s[j][i]!='.':
            f=0
            break
    if f:
        dels.append(i)



for i in dels:
    for j in range(len(s)):
        s[j]=s[j][:i]+' '+s[j][i+1:]

for i in s:
    for j in i:
        if j!=' ':
            print(j,end='')
    print()

Submission status: Accepted

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

dots = [input() for _ in range(H)]

newdots = []
for dot in dots:
    if dot == '.' * W:
        pass
    else:
        newdots.append(dot)


newdots2 = list(zip(*newdots))
dots = []
for dot in newdots2:
    flag = True
    for d in dot:
        if d == '#':
            flag = False

    if flag is False:
        dots.append(dot)

newdots3 = list(zip(*dots))
for d in newdots3:
    print("".join(d))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 18 00:01:41 2018

@author: Yuya
"""

n, m=map(int, input().split())

ans = []
c = 0

for i in range(n):
    tmp=list(input())
    f = 1
    for j in range(m):
        if tmp[j]=="#":
            f = -1
    if f<0:
        ans.append(tmp)
        c+=1


ans2 = [["0" for i in range(c)] for j in range(m)]

for i in range(m):
    for j in range(c):
        ans2[i][j] = ans[j][i]


d = m

for i in range(m-1, -1, -1):
    f = 1
    for j in range(c):
        if ans2[i][j]=="#":
            f = -1
    if f>0:
        del ans2[i]
        d-=1
        


ans3 = [["0" for i in range(d)] for j in range(c)]

for i in range(d):
    for j in range(c):
        ans3[j][i] = ans2[i][j]



for i in range(c):
    print(''.join(ans3[i]))

Submission status: Accepted

Solution code:
import numpy as np

h, w = [int(x) for x in input().split()]

a = []
for i in range(h):
    ab = input()
    if '#' in ab:
        a.append(ab)

a2 = []
for i in range(w):
    b = [e[i] for e in a]
    if '#' in b:
        a2.append(b)

a = np.array(a2).T

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

Submission status: Accepted

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

# for r in table:
#     print(r)

# row
for i in range(h):
    # print(h-i)
    row = table[h-1-i]
    row = list(set(row))
    if row == ["."]:
        table.pop(h-1-i)

# print("=========")
# for r in table:
#     print(r)

# col
l = []
for j in range(w):
    # print("==")
    # print(w-j)
    col = [r[w-1-j] for r in table]
    # print(col)
    col = list(set(col))
    if col == ["."]:
        # print("YY")
        l.append(w-1-j)
        # for i in range(h):
        #     table[i] = table[i].pop(w-1-j)


# print("=========")
# for r in table:
#     print(r)

out = []
for r in table:
    ll = list(r)
    for ind in l:
        ll.pop(ind)

    out.append("".join(ll))


# print("=========")
for r in out:
    print(r)

Submission status: Accepted

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

    ans = f(H, W, a)
    for x in ans:
        print(*x, sep="")


def f(H, W, a):
    b = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    if not b:
        return [[]]

    idxes = []
    for x in range(len(a[0])):
        y = sum(1 for i in range(len(b)) if b[i][x] == ".")
        if y != len(b):
            idxes.append(x)

    if not idxes:
        return [[]]

    ans = []
    for i in range(len(b)):
        line = []
        for j in range(len(a[0])):
            if j in idxes:
                line.append(b[i][j])
        ans.append(line)

    return ans


if __name__ == '__main__':
    main()