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:
a = list(map(int,input().split()))
h = a[0]
w = a[1]
li=[input() for i in range(h)]

ans = 0
minans = 0
flag = 0
row = [False] * h
col = [False] * w
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            row[i]=True
            col[j]= True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(li[i][j],end ="")
                
        print()

Submission status: Accepted

Solution code:
h,w= map(int,input().split())
l = list()
m = 0
for i in range(h):
  c = input()
  if "#" in c:
    b = [ w for w in range(len(c)) if c[w] == "#" ]
    l.append(b)
    if m < max(b) : m = max(b)
p = list()
for i in range(m) :
  for j in l:
    if i in j: break
  else:
    p.append(i)
for j in range(len(l)):
  for e in range(len(l[j])):
    cnt = 0
    for q in p:
      if l[j][e] > q : cnt += 1
    l[j][e]  = l[j][e]  - cnt
m = 0
for i in l:
  if m < max(i) : m = max(i)
for i in l:
  t = ""
  for j in range(m+1):
    if j in i : t = t + "#"
    else: t = t + "."
  print(t)

Submission status: Accepted

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

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:
def adjust(array):
    # 調整
    re_array = []
    for arr in array:
        a = set(arr)
        if len(a) == 1 and ''.join(a) == '.':
            continue
        else:
            re_array.append(arr)
    return re_array

# 入力
H, W = map(int, input().split())
array = [list(input()) for _ in range(H)]

# 横
array = adjust(array)

# 縦
array = list(zip(*array))
array = adjust(array)

# 戻す
array = list(zip(*array))

# 出力
for arr in array:
    print(''.join(arr))

Submission status: Accepted

Solution code:
h, w = [int(v) for v in input().split()]
a = []
for i in range(h):
    row = input()
    if '#' in row:
        a.append(list(row))

remove_column = []
for j in range(w):
    if len([True for v in a if v[j] == '#']) == 0:
        remove_column.append(j)
remove_column = remove_column[::-1]

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

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

Submission status: Accepted

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

temp = []
for i in range(h):
    if A[i] == ['.' for _ in range(w)]:
        temp.append(i - len(temp))
h -= len(temp)
for i in temp:
    A.pop(i)

B = []
for i in range(w):
    B_row = []
    for v in A:
        B_row.append(v[i])
    B.append(B_row)

temp = []
for i in range(w):
    if B[i] == ['.' for _ in range(h)]:
        temp.append(i - len(temp))
for i in temp:
    B.pop(i)
w -= len(temp)

C = []
for i in range(h):
    C_row = []
    for v in B:
        C_row.append(v[i])
    C.append(C_row)

for r in C:
    for c in r:
        print(c, end='')
    print()

Submission status: Accepted

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

hc = 0
a=[]
for _ in [0]*h:
  x = list(input())
  if "#" in x:
    a += [x]
    hc += 1

wc = 0
b=[]
for i in range(w):
  x = [a[k][i] for k in range(hc)]
  if "#" in x:
    b += [x]
    wc += 1

for i in range(hc):
  print("".join([b[k][i] for k in range(wc)]))

Submission status: Accepted

Solution code:
h, w = [int(_) for _ in input().split()]
a = [input() for i in range(h)]
a = ["".join(row) for row in zip(*a) if row.count("#") > 0]
a = ["".join(row) for row in zip(*a) if row.count("#") > 0]
print("\n".join(a))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
ac = [0 for i in range(w)]
for i in range(h):
    temp = list(input())
    for j in range(w):
        if temp[j] == '#':
            ac[j] += 1
    if '#' in temp:
        a.append(temp)
    else:
        h -= 1
for j in range(h):
    ans = ''
    for i in range(w):
        if ac[i] != 0:
            ans += a[j][i]
    print(ans)

Submission status: Accepted

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

S = []
for i in range(H):
    if T[i] == "." * W:
        continue
    else:
        S.append(list(T[i]))

m = len(S)
Z = [[] for i in range(m)]
for i in range(W):
    flag = False
    for j in range(m):
        if S[j][i] == "#":
            break
        if j == m - 1:
            flag = True
    if flag:
        continue
    else:
        for j in range(m):
            Z[j].append(S[j][i])

for i in range(m):
    print("".join(Z[i]))

Submission status: Accepted

Solution code:
import numpy as np
lis = []
fragone = False
fraglast = False
row,num = list(map(int,input().split()))
for i in range(row):
  lis.append(list(input()))
arr = np.array(lis)
for nikai in range(2):
  arr = arr[np.any(arr == "#",axis=1), :]
  arr = arr.T
for item in arr:
  print("".join(item))

Submission status: Accepted

Solution code:
from sys import stdin

H, W = [int(i) for i in stdin.readline().rstrip().split()]
a = [stdin.readline().rstrip() for _ in range(H)]

del_row = []

for i in range(len(a)):
    all_while = True
    s = a[i]
    for c in s:
        if c == '#':
            all_while = False
            break
    if all_while:
        del_row.append(i - len(del_row))

for i in del_row:
    a.pop(i)

a_t = []
for col in range(W):
    s = ''
    for row in range(len(a)):
        s += a[row][col]
    a_t.append(s)

del_row = []

for i in range(len(a_t)):
    all_while = True
    s = a_t[i]
    for c in s:
        if c == '#':
            all_while = False
            break
    if all_while:
        del_row.append(i - len(del_row))

for i in del_row:
    a_t.pop(i)

a = []
for col in range(len(a_t[0])):
    s = ''
    for row in range(len(a_t)):
        s += a_t[row][col]
    a.append(s)

for i in a:
    print(i)

Submission status: Accepted

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

a = [row for row in a if not all(map(lambda i: i == ".", row))]
a_T = [col for col in zip(*a) if not all(map(lambda i: i == ".", col))]
for row in zip(*a_T):
    print("".join(row))

Submission status: Accepted

Solution code:
import numpy as np
H,W = map(int, input().split())
a = [list(input()) for i in range(H)]
sub = {".": 0, "#": 1}
a = [[sub.get(x,x) for x in ai] for ai in a]
tmp = np.array(a)
tmp = tmp[:, ~(np.sum(tmp, 0) == 0)] # delete all 0 column
tmp = tmp[~(np.sum(tmp, 1) == 0), :] # delete all 0 row
sub2 = {0: ".", 1:"#"}
ans = [[sub2.get(x,x) for x in tmpi] for tmpi in tmp]
for ansi in ans:
    print("{}".format("".join(ansi)))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
list_prob = []
for i in range(0,h):
    list_prob.append(list(str(input())))
i = 0
while i < h:
    #print(i)
    if list_prob[i].count("#") == 0:
        del list_prob[i]
        h -= 1
        i -= 1
    i += 1
    #print(list_prob)

#print(list_prob)
j = 0
while j < w:
    list_j = []
    for i in range(0,h):
        list_j.append(list_prob[i][j])
    if list_j.count("#") == 0:
        for i in range(0,h):
            del list_prob[i][j]
        w -= 1
        j -= 1
    j += 1

for row in list_prob:
    print("".join(row))

Submission status: Accepted

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

newGrid = []
for i in range(h):
    a = list(input())
    for j,a_j in enumerate(a):
        if a_j == "#":
            newGrid.append(a)
            break
        else:
            continue

ans = []
for j in range(w):
    for i in range(len(newGrid)):
        if newGrid[i][j] == "#":
            ans.append([newGrid[k][j] for k in range(len(newGrid))])
            break
        else:
            continue
            
for ansi in list(zip(*ans)):
    print("".join(ansi))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
grid = np.array([], dtype=np.int)
for i in range(H):
    grid = np.append(grid, np.array([c=="." for c in input()]))

grid = grid.reshape(H,W)
row_test = np.where(np.sum(grid, axis=1)==W)
col_test = np.where(np.sum(grid, axis=0)==H)

grid = np.delete(grid, row_test[0], axis=0)
grid = np.delete(grid, col_test[0], axis=1)

for r in grid:
    res = ''
    for v in r:
        if v == 1:
            res += '.'
        else:
            res += '#'
    print(res)

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
A = [input() for _ in range(H)]
ind_H = []
ind_W = []
for h,a in enumerate(A):
    if '#' in a:
        ind_H.append(h)
        for w,s in enumerate(a):
            if s == '#':
                ind_W.append(w)
for h in ind_H:
    ans = ''
    for w in range(W):
        if w in ind_W:
            ans += A[h][w]
    print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = []
for i in range(h):
  temp = list(input())
  if not temp.count('.') == w:
    grid.append(temp)

remove = []

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

for i in range(len(grid)):
  ans = ''
  for j in range(len(grid[0])):
    if not j in remove:
      ans += grid[i][j]
  
  print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for i in range(h)]
b=[]
d=[]
for j in range(h):
 if int('#' in a[j])==1:b.append(a[j])
for l in range(w):
  c=0
  for k in range(len(b)):
    if list(b[k])[l]=='#':c+=1
  if c!=0:d.append(l)
for m in range(len(b)):
  x=[]
  for n in d:
    x.append(b[m][n])
  x=''.join(x)
  print(x)

Submission status: Accepted

Solution code:
H, W = map(int, input().split(" "))
A=[]
for i in range(H):
    tmp = input()
    A.append ([c  for c in tmp])
    
# print (A)

h=H
w=W
for i in range(H-1,-1,-1):
    cnt = 0    
    for j in range(W):
        if A[i][j] == ".":
            cnt += 1


    if cnt == W:
        h -= 1
        for ii in range(i, H-1):
            for jj in range(W):
                A[ii][jj] = A[ii+1][jj]

for j in range(W-1,-1,-1):
    cnt = 0    
    for i in range(h):
        if A[i][j] == ".":
            cnt += 1


    if cnt == h:
        w -= 1
        for jj in range(j, W-1):
            for ii in range(h):
                A[ii][jj] = A[ii][jj+1]

def printA(A, h, w):
    for i in range(h):
        st = ""
        for j in range(w):
            st += (A[i][j])

        print (st)    

printA(A, h, w)

Submission status: Accepted

Solution code:
h,w = map(int, raw_input().split())
m = [ raw_input() for _ in range(h) ]
hl = [ True for _ in range(h) ]
wl = [ True for _ in range(w) ]
for y in range(h):
    for x in range(w):
        if m[y][x] == '#':
            hl[y] = False
            wl[x] = False
for y in range(h):
    if hl[y]:
        continue
    s = ""
    for x in range(w):
        if wl[x]:
            continue
        s += m[y][x]
    print s

Submission status: Accepted

Solution code:
# coding: utf-8


def main():
    h, w = map(int, input().split())
    a = []

    # 「すべて白」以外の行を登録
    for _ in range(h):
        src = str(input())
        if len(src.replace('.', '')) > 0:
            a.append(src)

    # col行目がすべて白でないインデックスを取得
    blackpos = []
    for col in range(w):
        white = 0
        for row in range(len(a)):
            if a[row][col] == '.':
                white += 1
        if white != len(a):
            blackpos.append(col)

    # すべて白でないindexのもののみprint
    for row in range(len(a)):
        for col in blackpos:
            print(a[row][col], end='')
        print()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import compress

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

nonwhiterow = [any(c == '#' for c in row) for row in grid]
nonwhitecol = [any(row[i] == '#' for row in grid) for i in range(W)]

for row in compress(grid, nonwhiterow):
    comp = compress(row,  nonwhitecol)
    print(''.join(comp))

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np
h,w = map(int,input().split())
mat = []
for i in range(h):
    mat.append(list(input()))
mat = np.array(mat)
#mat=np.array([['.','#'],['#','#']])#test
isDot = mat == '.'
y = list(np.where(np.mean(isDot,axis=0)!=1)[0])
x = list(np.where(np.mean(isDot,axis=1)!=1)[0])
output = mat[np.ix_(x,y)]
for line in output:
    print("".join(line))

Submission status: Accepted

Solution code:
"""
B - Grid Compression
ex in )
4 4
##.#
....
##.#
.#.#

ex out)
###
###
.##
"""

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

matrix = []
for h in range(H):
    line = list(input())
    
    line_num = []
    for part in line:
        line_num.append(part)
    
    matrix.append(line_num)

leave_h = []
for h in range(H):
    for w in range(W):
        # 黒ならのこす
        if matrix[h][w] == "#":
            leave_h.append(h)
            break

leave_w = []
for w in range(W):
    for h in range(len(matrix)):
        
        # 黒ならのこす
        if matrix[h][w] == "#":
            leave_w.append(w)
            break


for h in range(H):
    if h not in leave_h:
        continue

    for w in range(W):
        if w not in leave_w:
            continue

        print(matrix[h][w], end="")
    
    print()

Submission status: Accepted

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

r = [False for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            r[i] = True
            break
c = [False for _ in range(w)]
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            c[i] = True
            break
for i in range(h):
    if r[i]:
        s = ""
        for j in range(w):
            if c[j]:
                s += a[i][j]
        print(s)

Submission status: Accepted

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

A = []
for i in range(H):
    a = input()
    if "#" in a: A.append(a)
        
A = list(zip(*A))

B = []
for a in A:
    if "#" in a: B.append(a)
        
B = list(zip(*B))

for b in B:
    print("".join(b))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
index1=0
listForList = []
while index1<h:
    list1 = list(input())
    if "#" in list1:
        listForList.append(list1)
    index1+=1

listForIndex=[]
index2 =0
while index2<w:
    index3=0
    flag =0
    while index3<len(listForList):
        if listForList[index3][index2]=="#":
            flag=1
        index3+=1
    if flag==0:
        listForIndex.append(index2)
    index2+=1

if len(listForIndex)>0:
    for index4 in listForIndex:
        index5=0
        while index5<len(listForList):
            listForList[index5][index4] = ""
            index5+=1

for list2 in listForList:
    print("".join(list2))

Submission status: Accepted

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

n_black_col = [0]*W
n_black_row = []

inp = []
for row in range(H):
    tmp = input()
    inp.append(tmp)
    r =[1 if a == "." else 0 for a in tmp]
    n_black_col = [n_black_col[i] + r[i] for i in range(W)]
    n_black_row.append(sum(r))

remove_col = []
remove_row = []
for ind, i in enumerate(n_black_col):
    if i == H:
        remove_col.append(ind)
for ind, i in enumerate(n_black_row):
    if i == W:
        remove_row.append(ind)

for i in range(H):
    if i in remove_row:
        continue
    str = ""
    for j in range(W):
        
        if j in	remove_col:
            continue
        str += inp[i][j]
    print(str)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()
Grid = []
for _ in range(H):
    s = ns()
    if '#' in s:
        Grid.append(list(s))

h = len(Grid)
res = []
for i in range(W):
    s = ''
    for j in range(h):
        s += Grid[j][i]
    if '#' in s:
        res.append(s)

for i in range(len(res[0])):
    s = ''
    for j in range(len(res)):
        s += res[j][i]
    print(s)

Submission status: Accepted

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

squares = []
for i in range(h):
    row = list(input())
    squares.append(row)

while True:
    continue_judge = False

    for i,l in enumerate(squares): # 横を消す
        if "#" not in l:
            squares.pop(i)
            h -= 1

    for i in range(w): # 縦を消す
        delete_judge = True

        for l in squares:
            if l[i] == "#":
                delete_judge = False
                break

        if delete_judge == True:
            for l in squares:
                l.pop(i)
            w -= 1
            continue_judge = True
            break

    if continue_judge == False:
        break


for l in squares:
    for i in l:
        print(i, end = "")
    print("")

Submission status: Accepted

Solution code:
h, w = [ int(i) for i in input().split()]
grid = [list(input()) for j in range(h)]
isOkColumn = [ 0 for i in range(w)]
isOkRow = [0 for i in range(h)]

for r in range(h):
    if '#' in grid[r]:
        isOkRow[r] = 1
    for c in range(w):
        if grid[r][c] == '#':
            isOkColumn[c] = 1

for r in range(h):
    if isOkRow[r] == 1:
        r_g = ''
        for c in range(w):
            if isOkRow[r] == 1 and isOkColumn[c] == 1:
                r_g += grid[r][c]
        print(r_g)

Submission status: Accepted

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

for i in range(h):
    count = 0
    for j in range(w):
        if a[i][j][0] == ".":
            count += 1
    if count == w:
        for j in range(w):
            a[i][j][1] = True

for i in range(w):
    count = 0
    for j in range(h):
        if a[j][i][0] == ".":
            count += 1
    if count == h:
        for j in range(h):
            a[j][i][1] = True

for i in a:
    flag = False
    for j in i:
        if not j[1]:
            print(j[0],end = "")
            flag = True
    if flag:
        print("")

Submission status: Accepted

Solution code:

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

M = []
for i in range(H):
	M.append(raw_input())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	if flag_list_H[i]:
		answer = ""
		for j in range(W):
			if flag_list_W[j]:
				answer+=M[i][j]
		print answer

Submission status: Accepted

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

row = [False]*h
column = [False]*w

for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      row[i] = True
      column[j] = True

for i in range(h):
  if row[i]:
    for j in range(w):
      if column[j]:
        print(a[i][j],end = "")
    print()

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())
a = list()
for i in range(n):
    a.append(list(input()))
line = np.array(a)
delete_r,delete_g=list(),list()
for i in range(n):
    if "#" not in line[i]:
        delete_g.append(i)
line = np.delete(line,delete_g,0)
for i in range(m):
    if "#" not in line[:,i]:
        delete_r.append(i)
line = np.delete(line,delete_r,1)
for i in line:
    for j in i:
        print(j,end="")
    print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
bwmap=[]
hlist=[]
for i in range(H):
    a=input()
    if a=='.'*W:
        bwmap.append(a)
    else:
        hlist.append(i)
        bwmap.append(a)
wlist=[]
for j in range(W):
    for i in range(H):
        if bwmap[i][j]=='#' :
            wlist.append(j)
            break
        if i==H-1:
            pass
result=[]
for i in hlist:
    res=''
    for j in wlist:
        res=res+bwmap[i][j]
    print(res)

Submission status: Accepted

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

goodx = [False] * h
goody = [False] * w

for i in range(h):
  for j in range(w):
#    print("i={}\tj={}\tboard={}".format(i,j,board[i][j]))
    if board[i][j] == '#':
      goodx[i] = True
      goody[j] = True

for i in range(h):
  if goodx[i]:
    for j in range(w):
      if goody[j]:
        print(board[i][j], end='')
    print("")

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
lines = np.array([[i for i in input()] for _ in range(H)])
lines = lines[np.any(lines=="#", axis=1)]
lines = lines[:, np.any(lines=="#", axis=0)]

ans = ""
for i in lines:
  ans += "".join(i) + "\n"
ans = ans[:-1]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


H, W = map(int, input().split())
lt = []

for i in range(H):
  lt += [list(input())]

  
def show(mat_):
  ptn = "%s" * mat_.shape[1]
  for row in mat_:
    print(ptn % tuple(row))
    
mat = np.array(lt)

mat = mat[:, ~np.all(mat==".", axis=0)]
mat = mat[~np.all(mat==".", axis=1), :]
show(mat)

Submission status: Accepted

Solution code:
h, w = (int(i) for i in input().split(' '))
m = []

def trans(string, h ,w):
    m = []
    for i in range(0, w):
        m.append(string[i::w])

    return m, w, h

def cut_dot(string_list, h, w):
    m = []
    cnt = 0
    for i in range(h):
        if string_list[i].count('.') != w:
            m.append(string_list[i])
        else:
            cnt += 1
    if cnt:
        return m, h-cnt, w, True
    else:
        return m, h-cnt, w, False

for i in range(h):
    m.append(input())

loop = True
while loop:
    m, h ,w, loop = cut_dot(m,h,w)
    if loop:
        m, h, w = trans(''.join(m), h, w)
        
for i in m:
    print(i)

Submission status: Accepted

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

# Filtering the data if any "#" are existed in the each row or col
# Usage: filter(lambda row: <filtering condition>, grid or zip(*grid)) 
# If true, the row is not be deleted
# (Do not use if statement!)
row_compressed_grid = list(filter(lambda row: any(x == "#" for x in row), grid))
compressed_grid = list(filter(lambda col: any(x == "#" for x in col), zip(*row_compressed_grid)))
# list -> string and out
for row in zip(*compressed_grid):
    print("".join(row))

Submission status: Accepted

Solution code:
h,w= map(int,input().split())
# 二重配列
arr = [list(input()) for i in range(h)]

y = len(arr[0])
x = len(arr)

arr2 = [[0 for i in range(y)] for j in range(x)]

for i in range(0,x):
    if arr[i].count('#')!=0:
        for j in range(0,y):
            arr2[i][j]+=1

for j in range(0,y):
    f =[False]
    for i in range(0,x):
        if arr[i][j]=='#':
            f[0]=True
            break
    if f[0]==True:
        for i in range(0,x):
            arr2[i][j]+=1

for i in range(0,x):
    j = 0
    while((arr2[i].count(1)!=0)or(arr2[i].count(0)!=0)):
        if arr2[i][j]<2:
            del(arr[i][j])
            del(arr2[i][j])
            j -=1
        j += 1

for i in range(0,x):
    if len(arr[i])==0:
        continue
    print("".join(arr[i]))

Submission status: Accepted

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

w_chk = [1]*W
h_chk = [1]*H
stock = []

for i in range(H):
        grid = list(input())
        stock.append(grid)
        for j in range(W):
            if not grid[j] == '.':
                w_chk[j] *= 0
                h_chk[i] *= 0

w_chk = [i for i, x in enumerate(w_chk) if x == 0]

for i in range(H):
    if h_chk[i] == 1:
        continue
    for j in w_chk:
        print(stock[i][j], end='')
    print('\n')

Submission status: Accepted

Solution code:
def solve(h, w, a):
    rs = []
    for r in range(h):
        ok = True
        for c in range(w):
            if a[r][c] == "#":
                ok = False
                break
        if not ok:
            rs.append(r)
    cs = []
    for c in range(w):
        ok = True
        for r in range(h):
            if a[r][c] == "#":
                ok = False
                break
        if not ok:
            cs.append(c)
    res = "\n".join(map(lambda r: "".join(map(lambda c: a[r][c], cs)), rs))
    return res

assert solve(4,4,["##.#","....","##.#",".#.#"]) == "###\n###\n.##"
assert solve(3,3,["#..",".#.","..#"]) == "#..\n.#.\n..#"
assert solve(4,5,[".....",".....","..#..","....."]) == "#"
h, w = map(int, raw_input().split())
a = []
for r in range(h):
    a.append(raw_input())
print solve(h, w, a)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(input())
row = [False]*H
col = [False]*W
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True
for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(a[i][j], end = "")
        print("", end = "\n")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
list = []
def isAllWhite(raw):
    for char in raw:
        if char != ".":
            return(False)
    return(True)

for i in range(H):
    raw = input()
    if isAllWhite(raw):
        continue
    else:
        list.append(raw)

def isColWhite(list,col):
    L = len(list)
    for i in range(L):
        if list[i][col] != ".":
            return(False)
    return(True)

ans = [[] for _ in range(len(list))]
for j in range(len(list[0])):
    if isColWhite(list,j):
        continue
    else:
        for i in range(len(ans)):
            ans[i].append(list[i][j])
for raw in ans:
    print("".join(raw))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
mp = [input() for i in range(h)]
mp2 = []
for i in range(h):
    if mp[i]!='.'*w:
        mp2.append(mp[i])
space = []
for i in range(w):
    flag = True
    for j in range(len(mp2)):
        flag &= (mp2[j][i]=='.')
    if flag:
        space.append(i)
for i in range(len(mp2)):
    for j in range(w):
        if j in space:
            continue
        print(mp2[i][j],end='')
    print("")

Submission status: Accepted

Solution code:
import numpy as np

H, W = list(map(int, input().split()))
arr = np.array([list(input()) for i in range(H)])
arr = arr[(np.apply_along_axis(lambda line: '#' in line, 1, arr))]
arr = arr[:, (np.apply_along_axis(lambda line: '#' in line, 0, arr))]
for l in arr.tolist():
    print(''.join(l))

Submission status: Accepted

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

row = [False] * h
side = [False] * w

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

for i in range(h):
    if row[i]:
        for j in range(w):
            if side[j]:
                print(a[i][j], end='')
        print()

Submission status: Accepted

Solution code:
from array import array
from itertools import repeat
from operator import itemgetter


def main():
    height, width = map(int, input().split())

    grid = []
    for _ in repeat(None, height):
        grid.append(array('B', (int(c == '.') for c in input())))

    for index in range(height - 1, -1, -1):
        if all(grid[index]):
            del grid[index]

    for index in range(width - 1, -1, -1):
        if all(map(itemgetter(index), grid)):
            for row in grid:
                del row[index]

    for row in grid:
        print(''.join('.' if b else '#' for b in row))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


def f1(x):
    for i in range(W):
        if A[x][i] == '#':
            return False
    return True


def f2(x):
    for i in range(H):
        if A[i][x] == '#':
            return False
    return True


ng_col = [i for i in range(H) if f1(i)]
ng_row = [i for i in range(W) if f2(i)]

for i in range(H):
    if i in ng_col:
        continue
    for j in range(W):
        if j in ng_row:
            continue
        print(A[i][j], end='')
    print()

Submission status: Accepted

Solution code:
H, W=map(int, input().split())
a=[list(input()) for _ in range(H)]
b=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    if '#' in a[i]:
        for j in range(W):
            b[i][j]+=1
for j in range(W):
    if any(a[i][j]=='#' for i in range(H)):
        for k in range(H):
            b[k][j]+=1
for i in range(H):
    for j in range(W):
        if b[i][j]==2:
            print(a[i][j], end='')
    if 2 in b[i]:
        print('')

Submission status: Accepted

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

isUseRow = [True] * H
isUseCol = [True] * W

for i in range(H):
    isDelete = True
    for j in range(W):
        if(a[i][j] == '#'):
            isDelete = False
    if(isDelete == False):
        isUseRow[i] = False
for i in range(W):
    isDelete = True
    for j in range(H):
        if(a[j][i] == '#'):
            isDelete = False
    if(isDelete == False):
        isUseCol[i] = False

for i in range(H):
    s = ''
    for j in range(W):
        if(isUseRow[i] == False and isUseCol[j] == False):
            s += a[i][j]
    if(s != ''):
        print(s)