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:
row_num, col_num = (int(i) for i in input().split())
matrix = [ list(input()) for i in range(row_num)]
transpose_matrix = []
for i in range(col_num):
    transpose_matrix.append([])
    for j in range(row_num):
        transpose_matrix[i].append(matrix[j][i])

empty_rows = []
# row check
for i,line in enumerate(matrix):
    if '#' in line:
        continue
    empty_rows.append(i)
empty_cols = []
# col check
for i,line in enumerate(transpose_matrix):
    if '#' in line:
        continue
    empty_cols.append(i)

for i in range(row_num):
    if i in empty_rows:
        continue
    for j in range(col_num):
        if j in empty_cols:
            continue
        print(matrix[i][j],end="")
    print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
for i in range(h):
    s=list(input())
    if s.count('#')!=0:
        a.append(s)



for i in range(len(a[0])):
    k = 0
    for j in range(len(a)):
        if a[j][i] == '.':
            k += 1
    if k == len(a):
        for j in range(len(a)):
            a[j][i] = 'a'
    k = 0
#print(a)

for i in range(len(a)):
    ans = ''
    for j in range(len(a[0])):
        if a[i][j] != 'a':
            ans += a[i][j]
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

#print(H,W)

dot=[]
for h in range(H):
    d=input().strip()
    if '#' in d:
        dot.append(list(d))
    
#print(dot)
dot = np.array(dot).T

dot2=[]
for d in range(len(dot)):
    if '#' in dot[d]:
        dot2.append(dot[d])

dot2 = np.array(dot2).T

#print(dot2)

for h in range(len(dot2)):
    print("".join(dot2[h]))

Submission status: Accepted

Solution code:
import copy

H,W = map(int,input().split())
a = []
for i in range(H):
    a.append(input().split())
aa = copy.copy(a)
#print(a)
aaa = 0
d = ""
for i in range(W):
    d += "."
for i in range(H):
    if a[i][0] == d:
        aa.pop(i-aaa)
        aaa += 1
#print(aa)
b = []
bb = ""
for i in range(W):
    for j in range(H-aaa):
        bb += aa[j][0][i]
    b.append(bb)
    bb = ""
#print(b)
d = ""
for i in range(H-aaa):
    d += "."
#print(d)
bc = copy.copy(b)
bbb = 0
for i in range(W):
    if b[i] == d:
        bc.pop(i-bbb)
        bbb += 1
#print(bc)
ans = []
ansc = ""
for i in range(H-aaa):
    for j in range(W-bbb):
        ansc += bc[j][i]
    ans.append(ansc)
    ansc = ""
#print(ans)
for i in range(H-aaa):
    print(ans[i])

Submission status: Accepted

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

for si in l[:]:
    if si.count('.') == len(si):
        l.remove(si)
h = len(l)

rl = []
for i in range(w):
    tl = []
    for js in l:
        tl.append(js[i])
    rl.append(''.join(tl))

for si in rl[:]:
    if si.count('.') == len(si):
        rl.remove(si)
w = len(rl[0])

al = []
for i in range(w):
    tl = []
    for js in rl:
        tl.append(js[i])
    al.append(''.join(tl))

for si in al:
    print(si)

Submission status: Accepted

Solution code:
H,W = list(map(int,input().split(" ")))
a = [list(input()) for i in range(H)]
h = []
w = []
for i in range(0,H):
    if "#" not in a[i]:
        h+=[(i,j,) for j in range(W)]

for i in range(W):
    for j in range(H):
        if a[j][i] != ".":
            break
        else:
            w.append(i)
    if w.count(i) == H:
        h+=[(k,i) for k in range(H)]
r = []
for i in range(H):
    c =[]
    for j in range(W):
        if (i,j,) in h:
            continue
        else:
            c.append(a[i][j])
    r.append(c)
for i in r:
    if i != []:
        print("".join(i))

Submission status: Accepted

Solution code:
# coding:utf-8
import numpy as np

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

mat = np.empty((H, W))
for i in range(H):
    for j in range(W):
        if cell[i][j] == '.':
            mat[i,j] = 0
        if cell[i][j] == '#':
            mat[i,j] = 1

col_del = np.all(mat == 0, axis=0)
row_del = np.all(mat == 0, axis=1)
col_index = np.where(col_del==True)
row_index = np.where(row_del==True)
#print(col_index)

res = np.delete(mat, row_index, axis=0)
res = np.delete(res, col_index, axis=1)
#print(res)
Hn = res.shape[0]
Wn = res.shape[1]

a =''
for i in range(Hn):
    ans = []
    for j in range(Wn):
        if res[i,j] == 0:
            ans.append('.')

        if res[i,j] == 1:
            ans.append('#')
    #print(ans)
    a += '\n' + ''.join(ans)

print(a)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
for i in range(h):
    ans = str(input())
    a.append((ans))
a_h = []
for i in range(h):
    check_h = False
    for j in range(w):
        if a[i][j] == '#':
            check_h = True
    if check_h:
        a_h.append(a[i])
ans = ['']*len(a_h)
for i in range(w):
    check_w = False
    for j in range(h):
        if a[j][i] == '#':
            check_w = True
    if check_w:
        for k in range(len(a_h)):
            ans[k] += a_h[k][i]
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
li = [input() for i in range(H)]
num_lists = []
num_lists2 = []
for i in range(H):
    if "#" in li[i]:
        print("") 
    else :
        num_lists.append(i)
for i in reversed(num_lists):
    li.pop(i)
n_H = len(li)
for i in range(W) :
    ch_li = []
    for j in range(n_H):
        ch_li.append(li[j][i])
    if "#" in ch_li:
        print("")
    else :
        num_lists2.append(i)
for i in reversed(num_lists2):
    for k in range(n_H) :
        li[k] = li[k][:i]+li[k][(i+1):]
        
for i in li:
    for j in i:
        print(j,end="")
    print()

Submission status: Accepted

Solution code:
HW = input()
masu = "none"
hw = HW.split()

Adata = []
for lop in range(int(hw[0])):
    A = input()
    Adata.append(A)

x = []
y = []
buf = ""
for lop in range(int(hw[0])):
    if str(Adata[lop]).find("#") == -1:
      x.append(lop)
      
for lop in range(int(hw[1])):
    for lop2 in range(int(hw[0])):
        buf = buf + str(Adata[lop2][lop])
    if str(buf).find("#") == -1:
        y.append(lop)
    buf = ""

for lop in range(len(x)-1,-1,-1):
    Adata.pop(x[lop])


ans = []
for lop in range(len(Adata)):
    buf = list(Adata[lop])
    for lop2 in range(len(y)-1,-1,-1):
        buf.pop(y[lop2])
    ans.append(buf)

for lop in range(len(ans)):
    ANS = ""
    for lop2 in range(len(ans[0])):
        ANS += ans[lop][lop2]
    print(ANS)

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
arr = [list(input()) for i in range(h)]
tmp = []
for i in arr:
    if "#" in i:
        tmp.append(i)
ans = [[] for i in range(len(tmp))]
for i in range(w):
    count = 0
    for j in range(len(tmp)):
        if tmp[j][i] == ".":
            count += 1
    if count < len(tmp):
        for j in range(len(ans)):
            ans[j].append(tmp[j][i])

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

Submission status: Accepted

Solution code:
import numpy as np

h,w=map(int,input().split())
tmp=[]
for i in range(h):
        a=list(input())
        tmp.append(a)
ans1=[]
if(w!=1):
    for i in range(h):
        if(len(set(tmp[i]))==1 and tmp[i][0]!="#"):
            ans1.append(i)
ans2=[]
tmp=list(map(list,zip(*tmp)))
if(h!=1):
    for i in range(w):
        if(len(set(tmp[i]))==1 and tmp[i][0]!="#"):
            ans2.append(i)
# print(ans1,ans2)
tmp=list(map(list,zip(*tmp)))
tmp=np.delete(tmp,ans1,axis=0)
tmp=np.delete(tmp,ans2,axis=1)
for i in range(len(tmp)):
    for j in range(len(tmp[0])):
        print(tmp[i][j],end="")
    print()

Submission status: Accepted

Solution code:
import sys
import numpy as np

def LI(): return [int(x) for x in sys.stdin.readline().split()]


if __name__ == "__main__":
    h, w = LI()
    a = []
    for _ in range(h):
        row = input()
        if row == '.'*w:
            continue
        else:
            a.append([e for e in row])

    b = []
    a_ = np.array(a).T
    for row in a_:
        if list(row) == ['.']*len(a):
            continue
        else:
            b.append(row)

    b = np.array(b).T
    for row in b:
        print(''.join(row))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
arr = []
count=0
for j in range(H):
    a=list(input())
    if '#' in a:
        arr.append(a)
    else:
        count=count+1
        pass

#print(arr)
arr=list(map(list, zip(*arr)))
#print(arr)
num=[]
for j in range(W):
#    print(j, arr[j])
    if '#' in arr[j]:
        pass
    else:
        num.append(j)  

#print(num)
num.reverse()
#print(num)

for i in num:
    del arr[i]
arr=list(map(list, zip(*arr)))

for i in range(H-count):
    print("".join(arr[i]))

Submission status: Accepted

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

arr = [raw_input() for i in range(h)]

ans = []
for i in range(h):
	count = 0
	for j in range(w):
		if arr[i][j] == '.':
			count += 1

	if count != w:
		ans.append(arr[i]) 


ret = [[] for i in range(len(ans))]
for i in range(w):
	count = 0
	for j in range(len(ans)):
		if ans[j][i] == '.':
			count += 1

	if count != len(ans):
		for j in range(len(ans)):
			ret[j].append(ans[j][i])

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

Submission status: Accepted

Solution code:
# vim: set fileencoding=utf-8:


def main():
    H, W = map(int, raw_input().split())
    a = [0] * H
    for i in xrange(H):
        a[i] = list(raw_input())

    b = a
    # 列の圧縮
    for i in xrange(W):
        v = ""
        for j in xrange(len(a)):
            v += a[j][i]

        if set(v) == set(".#") or set(v) == set("#"):
            pass
        else:
            for j in xrange(len(a)):
                a[j][i] = "e"

    b = []
    for ele in a:
        val = ''.join(ele).replace("e", "")
        b.append(list(val))

    for i in xrange(len(b)):
        v = ""
        for j in xrange(len(b[0])):
            v += b[i][j]

        if set(v) == set(".#") or set(v) == set("#"):
            pass
        else:
            for j in xrange(len(b[0])):
                b[i][j] = "e"

    c = []
    for ele in b:
        val = ''.join(ele).replace("e", "")
        if val != '':
            print(val)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

H,W=(int(i) for i in input().split())
li=[]
for i in range(0,H):
    li2=[]
    S1=input()
    for j in range(0,W):
        li2.append(S1[j])
        #print(li2)

    li.append(li2)
    
#print(li)
Flag=False
#横探索
for i in range(0,H):
    
    for j in range(0,W):
        if (li[i][j]=="." or li[i][j]=="Remove"):
            Flag=True
        else:
            Flag=False
            break

    if Flag==True:
         for j in range(0,W):
            li[i][j]="Remove"
          


    
#横探索
for i in range(0,W):
    
    for j in range(0,H):
         if (li[j][i]=="." or li[j][i]=="Remove"):
            Flag=True
         else:
            Flag=False
            break

    if Flag==True:
         for j in range(0,H):
            li[j][i]="Remove"
       
for i in range(0,H):
    for j in range(0,W):
        if (li[i][j]=="Remove"):
            li[i][j]=""

#print("ans")
for i in range(0,H):
    count=0
    for j in range(0,W):
        
        if (li[i][j]==""):
            Flag=True
            count+=1
        else:
            Flag=False
        
        print(str(li[i][j]),end="")

    if count!=W:
        print("")

Submission status: Accepted

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

W_bList = []
H_bList = []

#Width から黒のある列をリスト化する
for i in range(W):
    w = []
    for j in range(H):
        w.append(a[j][i])  

    #print("W",i, w)
    if len(set(w)) == 2 or set(w) == set("#"):
        W_bList.append(i)

#Hight から黒のある行をリスト化する
for i in range(H):
    h = []
    for j in range(W):
        h.append(a[i][j])  

    #print("H", i, h)
    if len(set(h)) == 2 or set(h) == set("#"):
        H_bList.append(i)

#リストから答えとなる部分だけを抜き出す
#print(W_bList, H_bList)

for hl in H_bList:

    ans = ""
    
    for wl in W_bList:
        ans += str(a[hl][wl])

    print(ans)

Submission status: Accepted

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

W_bList = []
H_bList = []

#Width から黒のある列をリスト化する
for i in range(W):
    w = []
    for j in range(H):
        w.append(a[j][i])  

    #print("W",i, w)
    if len(set(w)) == 2 or set(w) == set("#"):
        W_bList.append(i)

#Hight から黒のある行をリスト化する
for i in range(H):
    h = []
    for j in range(W):
        h.append(a[i][j])  

    #print("H", i, h)
    if len(set(h)) == 2 or set(h) == set("#"):
        H_bList.append(i)

#リストから答えとなる部分だけを抜き出す
#print(W_bList, H_bList)

for hl in H_bList:

    ans = ""
    
    for wl in W_bList:
        ans += str(a[hl][wl])

    print(ans)

Submission status: Accepted

Solution code:
"""
上手い方法思い付きませんでした（圧縮→行列転置→圧縮→行列転置は悪くなさそう）
～～～登場人物～～～
s：入力
ss：入力から行を圧縮したもの
　　（s[i]にピリオド以外のものがある場合にappendしたやつ）
  
answer：ssから頑張って列を圧縮したもの
       （ss[i][j]がすべてのjでピリオドだった場合のjをcolumn_compに格納
       　その後、column_compに含まれていないjにおいて、answer[i] += ss[i][j] ）

"""

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

s = []
for i in range(h):
  s.append(input())
#print(s)

#行を圧縮しましゅ
row = 0
ss = []
for i in range(h):
  if s[i].count(".") != w:
    ss.append(s[i])
    row += 1
#print(ss, row)
    
#列を圧縮しましゅ
column_comp = []
for j in range(w):
  period_count = 0
  for i in range(row):
#    print(s[j][i])
    if ss[i][j] == ".":
      period_count += 1
  if period_count == row:
    column_comp.append(j)
#    print(column_comp)

answer = ["" for i in range(row)]
for i in range(row):
  for j in range(w):
    if j not in column_comp:
      answer[i] += ss[i][j]
  print(answer[i])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from collections import deque

    la = list(map(int, input().split()))

    nl = deque([])

    for i in range(0, la[0]):
        nl.append(list(input()))

    for j in range(len(nl)):
        if '#' not in nl[j]:
            nl[j].clear()

    sl = [u for u in nl if u]

    for c in range(0, la[1]):
        zl = [row[c] for row in sl]
        # print(zl)
        if '#' not in zl:
            for d in sl:
                d[c] = ''

    for e in range(len(sl)):
        sl[e] = [u for u in sl[e] if u]

    for k in sl:
        print(''.join(k))

Submission status: Accepted

Solution code:
h,w = input().split()
h = int(h)
w = int(w)
inp = []
count = 0
for i in range(h):
    tmp_input = list(input())
    if '#' in tmp_input:
        inp.append(tmp_input)
    else:
        count += 1
inp2 = list(map(list,zip(*inp)))
youso = []
for i in range(w):
    if "#" in inp2[i]:
        pass
    else:
        youso.append(i)
youso.reverse()
if len(youso) != 0:
    for i in range(len(youso)):
        for j in range(h-count):
            del inp[j][youso[i]]
else:
    pass
for i in range(len(inp)):
    mojiretu = ''.join(inp[i])
    print(mojiretu)

Submission status: Accepted

Solution code:
import math
H,W=list(map(int,input().split()))
grid=[]
for i in range(H):
    grid.append(input())
after=[]
for i in range(H):
    if grid[i] != '.'*W:
        after.append(grid[i])

H = len(after)
W = len(after[0])

flag = []
for i in range(H):
    r = []
    for j in range(W):
        r.append(1)
    flag.append(r)

for j in range(W):
    c = ''
    for i in range(H):
        c = c+after[i][j]
    if c == '.'*H:
        for k in range(H):
            flag[k][j] = 0
            W -= 1
    else:
        pass
out=[]
for i in range(H):
    out.append([])

for i in range(H):
    for j in range(len(after[0])):
        if flag[i][j] == 1:
            out[i].append(after[i][j])
        else:
            pass

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

Submission status: Accepted

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

for h in range(H):
    s = input()
    if '#' in s:
        grid.append(s)

dl = []
ans = [''] * len(grid)
for i in range(W):
    l = ''
    for j in range(len(grid)):
        g = grid[j]
        ans[j] += g[i]
        l += g[i]
    if '#' not in l:
        for k in range(len(grid)):
            ans[k] = ans[k][:-1]

for i in range(len(ans)):
    str = ''
    for j in range(len(ans[i])):
        str += ans[i][j]
    print(str)

Submission status: Accepted

Solution code:
ys, xs = map(int, input().split())
mas = []
for y in range(ys):
    mas.append(list(input()))
import numpy as np
mas_new = []
mas = np.array(mas)

for ma in mas:
    if (ma == '.').sum() != xs:
        mas_new.append(ma.tolist())
        
mas = np.array(mas_new).T

mas_new = []

for ma in mas:
    if (ma == '.').sum() != mas.shape[1]:
        mas_new.append(ma.tolist())
    
mas = np.array(mas_new).T
mas = mas.tolist()
for ma in mas:
    print(''.join(ma))

Submission status: Accepted

Solution code:
def main():
    H, W = list(map(int, input().split(" ")))
    a = []
    for r in range(H):
        a += [input()]
    output = solve(H, W, a)
    for s in output:
        print(s)
    return

#________________________________________
#  Solve
#________________________________________
def solve(H, W, a):
    """
    解答のコード
    """
    index_list = []
    for _r in range(H):
        for _c in range(W):
            if a[_r][_c] is not ".":
                break
            if _c == W-1:
                index_list += [_r]
    j = 0
    for i in index_list:
        del a[i-j]
        j += 1

    index_list = []
    a = list(map(list, zip(*a)))
    for _r in range(len(a)):
        for _c in range(len(a[0])):
            if a[_r][_c] is not ".":
                break
            if _c == len(a[0])-1:
                index_list += [_r]
    j = 0
    for i in index_list:
        del a[i-j]
        j += 1
    a = list(map(list, zip(*a)))
    a = [ "".join(a[i]) for i in range(len(a))]
    return a
#________________________________________


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def compression(init, matrix):
	
	mir = []
	
	for row in matrix:
		if "#"in row:
			mir.append(row)
	matrix = []
	
	mir = list(map(list, zip(*mir)))
	
	for row in mir:
		if "#"in row:
			matrix.append(row)
		
	matrix = list(map(list, zip(*matrix)))	
			
	
	return matrix


init = input().split(" ")
init = [int(c) for c in init]

matrix = [[] for j in range(init[0])]

for j in range(init[0]):
	matrix[j] = input()

result = compression(init, matrix)
for row in result:
	print("".join(row))

Submission status: Accepted

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

grid = []
for _ in range(H):
    row = input()
    if row[0] == "." and len(set(row)) == 1:
        H -= 1
        continue
    grid.append(row)

for i in range(W-1, -1, -1):
    if grid[0][i] == "#" or len(set([row[i] for row in grid ])) != 1:
        continue
    for h in range(H):
        new_row = ""
        if i > 0:
            new_row += grid[h][:i]
        if i < W-1:
            new_row += grid[h][i+1:]
        grid[h] = new_row

for row in grid:
    print(row)

Submission status: Accepted

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

import numpy as np

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

masu = []
res = []
str1 = '.' * W

for i in range(H):
	str2 = input()
	if str1 != str2:
		masu.append(str2)

l = ['.'] * len(masu)
for i in range(W):
	tmp = [k[i] for k in masu]
	if tmp != l:
		res.append(tmp)

ww = len(res[0])
hh = len(res)
for i in range(ww):
	for j in range(hh):
		print(res[j][i], end='')
	print('')

Submission status: Accepted

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

field = [[s for s in input()] for _ in range(h)]

tmp = ["" for _ in range(w)]
for i in range(h):
    for j in range(w):
        tmp[j] += field[i][j]

row = [s.count("#") == 0 for s in field]
col = [s.count("#") == 0 for s in tmp]

for i,r in enumerate(row):
    for j,c in enumerate(col):
       if not (r or c):
           print(field[i][j],end="")

    print()

Submission status: Accepted

Solution code:
H,W = [int(i) for i in input().split()]
table = []
for i in range(H):
  table.append(input())
 
table_ = []
for i in range(H):
  for j in range(W):
      if table[i][j] == '#':
          table_.append(table[i])
          break

ans = []
for i in range((W)):
    for j in range(len(table)):
        if table[j][i] == '#':
            ans.append(i)
            break

for line in table_:
    for i in ans:
        print(line[i],end = '')
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
b = []
c = []
i = 0
j = 0
k = 0
while i < H:
    moji = input()
    if "#" in moji:
        a.append([m for m in moji])
    i += 1
while j < W:
    ls = [row[j] for row in a]
    if "#" in ls:
        b.append(ls)
    j += 1
while k < len(b[0]):
    ls = [row[k] for row in b]
    c.append(ls)
    k += 1
for row in c:
    print("".join(row))

Submission status: Accepted

Solution code:
import numpy as np

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

for h in range(H):
    i = input()
    if not '#' in i:
        continue

    for n in range(len(i)):
        a[n].append(i[n])

b = []
for x in a:
    if not '#' in x:
        continue
    b.append(x)

[print(''.join(x)) for x in np.array(b).T.tolist()]

Submission status: Accepted

Solution code:
import sys

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

#行削除
for line in a[:]:
    if line.count('.') == len(line):
        a.remove(line)

if len(a)==0:
    sys.exit

b = []

#転地
for row in range(len(a[0])):
    tmp = []
    for line in range(len(a)):
        tmp.append(a[line][row])
    b.append(tmp)    

for line in b[:]:
    if line.count('.') == len(line):
        b.remove(line)
c=[]
#転地
for row in range(len(b[0])):
    tmp = []
    for line in range(len(b)):
        tmp.append(b[line][row])
    c.append(tmp)    


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

Submission status: Accepted

Solution code:
import numpy as np

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

board = []
for i in range(n):
    l = list(input())
    board.append(l)
board = np.array(board, dtype='unicode')

tmp = []
for i in range(board.shape[0]):
    if sum(board[i, :] == '.') == board.shape[1]:
        tmp.append(i)
board = np.delete(board, tmp, axis=0)

tmp = []
for i in range(board.shape[1]):
    if sum(board[:, i] == '.') == board.shape[0]:
        tmp.append(i)
board = np.delete(board, tmp, axis=1)

for i in range(board.shape[0]):
    for j in range(board.shape[1]):
        print(board[i, j], end='')
    print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = ["" for i in range(H)]
h = [True for i in range(H)]
w = [False for i in range(W)]

for i in range(H):
	a[i] = input()
	if a[i] == "."*W:
		h[i] = False
	for j in range(W):
		if a[i][j] == "#":
			w[j] = True

for i in range(H):
	if h[i]:
		z = ""
		for j in range(W):
			if w[j]:
				z += a[i][j]
		print(z)

Submission status: Accepted

Solution code:
#coding: utf-8

h,w = map(int,raw_input().split())

a = []

for i in range(h): a.append(raw_input())

flags = [True] * (h+w)

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            flags[i] = False
            flags[h+j] = False

i = 0
while True:
    if i>h-1: break
    if flags[i]:
        del a[i]
        del flags[i]
        h -= 1
        i -= 1
    i += 1

i = 0
while True:
    if i>w-1: break
    if flags[h+i]:
        w -= 1
        del flags[h+i]
        for j in range(h):
            a[j] = a[j][:i] + a[j][i+1:]
        i -= 1
    i += 1

for i in range(h):
    print a[i]

Submission status: Accepted

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

for i in range(H):
    t = 0
    for j in range(W):
        if l[i][j] == '.':
            t += 1
    if t == W:
        del_list_H.append(i)

counter = len(del_list_H)
for i in range(counter):
    del l[del_list_H[i]]
    del_list_H = [x-1 for x in del_list_H]
    H -= 1

for i in range(W):
    t = 0
    for j in range(H):
        if l[j][i] == '.':
            t += 1
    if t == H:
        del_list_W.append(i)

counter = len(del_list_W)
for i in range(counter):
    for j in range(H):
        del l[j][del_list_W[i]]
    del_list_W = [x-1 for x in del_list_W]
    W -= 1


for i in range(len(l)):
    text = ''
    for j in range(len(l[i])):
        text += l[i][j]
    print(text)

Submission status: Accepted

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

b=[]
d=[]
k=0
for i in range(w):
    d.append(i)

for i in range(h):
    a=input()
    if a!="."*w:
        b.append(a)
    else:
        h-=1
        
for i in range(w):
    c=0
    for j in range(h):
        if b[j][i]=="#":
            c+=1
    if c==0:
        del(d[k])
    else:
        k+=1
            
for i in range(h):
    for j in d:
       sys.stdout.write(b[i][j]) 
    print("")

Submission status: Accepted

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

row=[]
for i in range(h):
     flag=False
     for j in range(w):
         if(a[i][j]=='#'):
             flag=True
             break
     if flag: row.append(i)
col=[]
for i in range(w):
     flag=False
     for j in range(h):
         if(a[j][i]=='#'):
             flag=True
             break
     if flag: col.append(i)
for i in row:
    s=''
    for j in col:
        s+=a[i][j]
    print(s)

Submission status: Accepted

Solution code:
#encoding utf-8

import numpy as np

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

a = np.zeros((H,W))

for h in range(H):
    line = list(input())
    # print(line)
    for w in range(W):
        if line[w] == "#":
            line[w] = 1
        else:
            line[w] = 0
    a[h] = line


delete_line = 0
for h in range(H):
    h = h - delete_line
    if np.allclose(a[h,:], np.zeros(W)):
        a = np.delete(a, h, 0)
        delete_line += 1

delete_row = 0
for w in range(W):
    w = w - delete_row
    if np.allclose(a[:,w], np.zeros((1,H-delete_line))):
        a = np.delete(a, w, 1)
        delete_row +=  1

b = np.array(a, dtype = str)

for h in range(H-delete_line):
    for w in range(W-delete_row):
        if a[h,w] == 1:
            b[h,w] = "#"
        else:
            b[h,w] = "."

for i in range(H-delete_line):
    print("".join(b[i,:]))

Submission status: Accepted

Solution code:
def pri(l):
    for i in l:
        print(i)
h, w = map(int, input().split())
a, ans = [], []
for _ in range(h):
    temp = ''.join(input())
    if not all([x == '.' for x in temp]):
        a.append(temp)
for temp in [''.join(s) for s in zip(*a)]:
    if not all([x == '.' for x in temp]):
        ans.append(temp)
pri([''.join(s) for s in zip(*ans)])

Submission status: Accepted

Solution code:
import warnings
import numpy as np
warnings.simplefilter(action='ignore', category=FutureWarning)

h, w = map(int,input().split())
table = np.empty((h,w))

for i in range(h):
	temp = [0 if x=="." else 1 for x in list(input())]
	for j in range(w):
		table[i][j] = temp[j]

new1 = table
# print(table)

c = 0

for i in range(h):
	if not 1 in table[i]:
		new1 = np.delete(new1, i-c, 0)
		c += 1

c = 0

for j in range(w):
	if not 1 in table[:,j]:
		new1 = np.delete(new1, j-c, 1)
		c += 1

table = new1
# print(table)

for i in range(len(table)):
	z = ""
	for j in range(len(table[0])):	
		if table[i][j] == 0:
			z = z + "."
		else:
			z = z + "#"
	print(z)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(list(input()))
for i in range(W):
    flag = True
    for j in range(H):
        if a[j][i] == '#':
            flag = False
    if flag:
        for k in range(H):
            a[k][i] = '-'
for i in a:
    if not '#' in i:
        continue
    for j in range(W):
        if i[j] != '-':
            print(i[j], end = '')
    print('')

Submission status: Accepted

Solution code:
#b1:マス目の初期状態
H,W = map(int,input().split())
b = [[0 for i in range(W)] for j in range(H)]
for i in range(0,H):
    line = input()
    for j in range(0,W):
        b[i][j] = line[j]
        
#全て白の行を見つける
x = []
for k in range(0,H):
    flag = True
    for k2 in range(W):
        if b[k][k2] is '#':
            flag = False
    if flag:
        x.append(k)
#全て白の列を見つける
y = []
for l in range(W):
    flag = True
    for m in range(H):
        if b[m][l] is '#':
            flag = False
    if flag:
        y.append(l)

#全て白の行と列を除いたマス目を作る
b2 = [[0 for i in range(W-len(y))] for j in range(H-len(x))]
c1,c2 = 0,0
for i in range(H):
    c2 = 0
    if i not in x:
        for j in range(W):
            if j not in y:
                b2[c1][c2]=b[i][j]
                c2 += 1
        c1 += 1

#表示
for i in range(H-len(x)):
    s = ""
    for j in range(W-len(y)):
        s += b2[i][j]
    print(s)

Submission status: Accepted

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

a = []
for i in range(h):
    line = input()
    aa = []
    for j in range(len(line)):
        aa.append(line[j])
    a.append(aa)

# horizontal
popList = []
for i in range(len(a)):
    isBlack = False
    for j in range(len(a[i])):
        if a[i][j] == "#":
            isBlack = True
    
    if isBlack == False:
        popList.append(i)

for i in range(len(popList)):
    a.pop(popList[i] - i)

# vertical
popList = []
for i in range(len(a[0])):
    isBlack = False
    for j in range(len(a)):
        if a[j][i] == "#":
            isBlack = True

    if isBlack == False:
        popList.append(i)

for i in range(len(popList)):
    for j in range(len(a)):
        a[j].pop(popList[i] - i)

# print
for i in a:
    for j in i:
        print(j, end="")
    print()