Problem:


Score : 200 points

Problem Statement

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

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

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

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

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

###
###
.##

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

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

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

Sample Input 3

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

Sample Output 3

#

Sample Input 4

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

Sample Output 4

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



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


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

Submission status: Accepted

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

h = []
w = []
for i in range(H):
    if A[i].count(".") == W:
        h.append(i)

for i in range(W):
    qwe = 0
    for j in range(H):
        if A[j][i] == ".":
            qwe += 1
        else:
            break
    if qwe == H:
        w.append(i)

p = 0
for i in h:
    A.pop(i-p)
    p += 1

p = 0
for i in w:
    i = i - p
    for j in range(len(A)):
        A[j] = A[j][:i] + A[j][i+1:]
    p += 1


for i in A:
    print(i)

Submission status: Accepted

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

for j, row in enumerate(a):

    tf = False
    for el in row:
        if el == '#':
            tf = True
    if tf is True:
        res4row.append(j)

for k, col in enumerate(a[0]):
    tf2 = False
    for row2 in a:
        if row2[k] == '#':
            tf2 = True
    if tf2 is True:
        res4col.append(k)

res = [[] for z in range(h)]
for num4row in res4row:
    # res.append([])
    for num4col in res4col:
        res[num4row].append(a[num4row][num4col])

for r in res:
    st = ''
    if len(r) != 0:
        for c in r:
            st = st + c
        print(st)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
i=0
while i<len(l):
    for j in range(len(l[0])):
        if l[i][j]!='.':
            i+=1
            break
    else:
        del(l[i])

i=0    
while i<len(l[0]):
    for j in range(len(l)):
        if  l[j][i]!='.':
            i+=1
            break
    else:
        for k in range(len(l)):
            del l[k][i]
i=0
for i in range(len(l)):
    s=''
    for j in range(len(l[0])):
        s=s+l[i][j]
    print(s)

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, raw_input().split())
a = []
for i in range(H):
	_a = list(raw_input())
	a.append(_a)
a = np.array(a)
b = a.copy()
while True:
	r_exist = False
	c_exist = False
	for i in range(len(a)):
		if not '#' in a[i, :]:
			b = np.delete(a, i, 0)
			r_exist = True
	a = b.copy()
	for i in range(len(b[0])):
		if not '#' in b[:, i]:
			a = np.delete(b, i, 1)
			c_exist = True
	b = a.copy()
	if not (r_exist or c_exist):
		break
for i in b:
	print ('').join(i)

Submission status: Accepted

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

ar_true = []
for i in range(H):
    if ar[i] != ['.'*W]:
        ar_true.append(ar[i])

ar_res_line = []
n_length = len(ar_true)
for i in range(W):
    flag = False
    for ii in range(n_length):
        if ar_true[ii][0][i] == '#':
            flag = True
    if flag:
        ar_res_line.append(i)

ar_res = []
for h in range(n_length):
    tmp = ''
    for i in range(len(ar_res_line)):
        tmp_line = ar_res_line[i]
        tmp += ar_true[h][0][tmp_line]
    ar_res.append(tmp)

for i in range(n_length):
    print(ar_res[i])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
grid=[[0 for i in range(M)] for j in range(N)]
moji=""
for i in range(N):
    moji=input()
    for j in range(len(moji)):
        grid[i][j]=moji[j:j+1]
    

X=0
Y=0
while(X<N or Y<M): # or Y<=M
    delflug=True
    if (X<N):
        for i in range(M):
            if grid[X][i]=="#":
                delflug=False
                break
        if delflug==True:
            del grid[X]
            N-=1
            X-=1
            
        X+=1    
    else:
        for i in range(N):
            if grid[i][Y]=="#":
                delflug=False
                break
        if delflug==True:
            for i in range(N):
                del grid[i][Y]
                
            M-=1
            Y-=1
            
        Y+=1    
for i in range(N):
    s="".join(grid[i])
    print(s)

Submission status: Accepted

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


matrix_1 = []
for i in range(H):
    if matrix[i] != "." * W:
        matrix_1.append(matrix[i])


matrix_2 = []
for i in range(W):
    a = ""
    for l in range(len(matrix_1)):
        a += matrix_1[l][i]
    matrix_2.append(a)


ans = []
k = len(matrix_1)
for i in range(W):
    if matrix_2[i] != "." * k:
        ans.append(matrix_2[i])


ans_2 = []
for i in range(len(ans[0])):
    a = ""
    for l in range(len(ans)):
        a += ans[l][i]
    ans_2.append(a)


for i in range(len(ans_2)):
    print(ans_2[i])

Submission status: Accepted

Solution code:
import numpy as np

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

for i in range(H-1, -1, -1):
    if not '#' in lst[i]:
        lst = np.delete(lst, i, 0)
lst = lst.T
for i in range(W-1, -1, -1):
    if not '#' in lst[i]:
        lst = np.delete(lst, i, 0)
lst = lst.T

for x in lst:
    for y in x:
        print(y, end='')
    print()

Submission status: Accepted

Solution code:
import sys

aa = input().strip().split()
h = int(aa[0])
w = int(aa[1])
a = [list(input().strip()) for _ in range(h)]
r = [list() for _ in range(2)]

for i in range(h):
    if a[i][0] == '.':
        flag = True

        for j in range(1, w):
            if a[i][j] != '.':
                flag = False
                break

        if flag:
            r[0].append(i)

for i in range(w):
    if a[0][i] == '.':
        flag = True

        for j in range(1, h):
            if a[j][i] != '.':
                flag = False
                break

        if flag:
            r[1].append(i)

for i in reversed(range(len(r[0]))):
    del a[r[0][i]]

for i in reversed(range(len(r[1]))):
    for j in reversed(range(len(a))):
        del a[j][r[1][i]]

for i in range(len(a)):
    for j in range(len(a[i])):
        sys.stdout.write(a[i][j])

    sys.stdout.write('\n')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

def checkCol(A, i):
    for j in range(len(A[i])):
        if A[i][j] == "#":
            return False
    return True

def checkLow(A, j):
    for i in range(len(A)):
        if A[i][j] == "#":
            return False
    return True

H, W = map(int, sys.stdin.readline().strip().split(" "))

A = []
for line in sys.stdin:
    A.append(list(line.strip()))

col = []
low = []
for i in range(len(A)):
    if checkCol(A, i):
        col.append(i)

for i in range(len(A[0])):
    if checkLow(A, i):
        low.append(i)

for i, al in enumerate(A):
    if i in col:
        continue
    for j, a in enumerate(A[i]):
        if j in low:
            continue
        sys.stdout.write(a)
    sys.stdout.write("\n")

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
grid = np.array([list(input()) for _ in range(H)])
grid_1 = grid[~np.all(grid == '.', axis = 1), :]
grid_2 = grid_1[:, ~np.all(grid == '.', axis = 0)]
for i in range(grid_2.shape[0]):
    print(''.join(grid_2[i]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
row_list = ['' for i in range(W)]
for i in range(H):
    line = input()
    if line == '.'*W:
        continue
    else:
        for j in range(W):
            row_list[j] = row_list[j] + line[j]
line_list = []
for i in range(W):
    if row_list[i] == '.' * len(row_list[i]):
        continue
    else:
        if line_list == []:
            for j in row_list[i]:
                line_list.append(j)
        else:
            for j in range(len(row_list[i])):
                line_list[j] = line_list[j] + row_list[i][j]
for i in line_list:
    print(i)

Submission status: Accepted

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

data = []
for i in range(h):
    _input = input()
    data.append([char for char in _input])

del_row_idx = []
for i, row in enumerate(data):
    tf = [char=='.' for char in row]
    flag = True
    for t in tf:
        flag *= t
    if flag:
        del_row_idx.append(i)

del_col_idx = []
for i in range(w):
    tf = [char=='.' for char in [row[i] for row in data]]
    flag = True
    for t in tf:
        flag *= t
    if flag:
        del_col_idx.append(i)

for idx in del_row_idx[::-1]:
    data.pop(idx)

for idx in del_col_idx[::-1]:
    for row in data:
        row.pop(idx)

for d in data:
    print(''.join(d))

Submission status: Accepted

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

h = 0
for i in range(H):
    inp = input()
    if inp == white:
        continue
    for j, c in enumerate(inp):
        a[j]+=c
    h+=1

b = ['' for _ in range(h)]
white = ['.' for _ in range(h)]
white = ''.join(white)

for i in range(W):
    inp = a[i]
    if inp == white:
        continue
    for j, c in enumerate(inp):
        b[j]+=c

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

Submission status: Accepted

Solution code:
import numpy as np

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

l = [];
for i in range(H):
	r = input()
	if set(r) != {'.'}:
		k = list(r)
		l.append(k)

d = []
for i in range(W):
	p = [[j[i]] for j in l]
	result = []
	for sublist in p:
	    for item in sublist:
	        result.append(item)
	if set(result) == {'.'}:
		d.append(i)

nl = np.array(l)
itr = 0
for x in range(len(d)):
	nl = np.delete(nl, d[x]-itr, 1)
	itr += 1

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = []
    for i in range(H):
        input_raw = read_func().strip().split()
        field.append(input_raw[0])
    is_all_white_raw = [True for i in range(H)]
    is_all_white_col = [True for i in range(W)]

    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                is_all_white_raw[i] = False
                break

    for j in range(W):
        for i in range(H):
            if field[i][j] == "#":
                is_all_white_col[j] = False
                break

    for i in range(H):
        if is_all_white_raw[i] == True:
            continue
        for j in range(W):
            if is_all_white_col[j] == True:
                continue
            sys.stdout.write(field[i][j])
        print

if __name__ == '__main__':
    main()

Submission status: Accepted

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

rows = []
for i in range(1,H+1):
    row = input()
    if row.count("#") > 0:
        rows.append(list(row))

cols = []
for j in range(W):
    col = ""
    for k in range(len(rows)):
        col += rows[k][j]

    if col.count("#") > 0:
        cols.append(col)
        
ans = []
for l in range(len(cols[0])):
    row = ""
    for m in range(len(cols)):
        row += cols[m][l]

    ans.append(row)
    
print("\n".join(ans))

Submission status: Accepted

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

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

a = []
for i in range(0,H):
    data = str(input())
    a.append(list(data))

for i in range(H-1,-1,-1):
    if '#' in a[i]:
        pass
    else:
        del a[i]

for i in range(W-1,-1,-1):
    check = 0
    for j in range(0,int(len(a))):
        if a[j][i] == "#":
            check = 1
            break
        else:
            pass
    if check == 0:
        for j in range(0,int(len(a))):
            del a[j][i]

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

Submission status: Accepted

Solution code:
na = lambda: list(map(int, input().split()))

h, w = na()
t = []
cnt = 0
for i in range(h):
    I = list(input())
    if not("#" in I):
        cnt += 1
        continue
    t.append(I)
output = []
for j in range(w):
    flag = False
    for i in range(h-cnt):
        if t[i][j] == "#":
            flag = True
    if flag:
        output.append(j)
for T in t:
    for num, i in enumerate(T):
        if num in output:
            print(i, end="")
    print()

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


h, w = inpl()
A = []
for i in range(h):
    a = list(input())
    A.append(a)

comp = []
for i in range(h):
    for j in range(w):
        if A[i][j] == '#':
            comp.append([1 for _ in range(w)])
            break
    else:
        comp.append([0 for _ in range(w)])

B = list(zip(*A))[:]
comp = list(zip(*comp))[:]
for i in range(w):
    for j in range(h):
        if B[i][j] == '#':
            # comp[i] = list(comp[i])
            break
    else:
        comp[i] = [0 for _ in range(h)]

comp = list(zip(*comp))[:]


ans = []
for i in range(h):
    tmp = []
    for j in range(w):
        if comp[i][j] == 1: tmp.append(A[i][j])
    if tmp != []:
        ans.append(tmp)


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

Submission status: Accepted

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

for w in range(W):
    t = []
    for h in range(H):
        t.append((L[h][w]))
    
    if '#' not in t:
        for h in range(H):
            L[h][w] = ""
            
for l in L:
    if "#" not in l:
        pass
    else:
        res.append(l)

for i in res:
    result = ''
    for j in i:
        result += j
    print(result)

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            a_new.append(a[i])
            break

a_ = list(zip(*a_new))
a_H  = len(a_)
a_W  = len(a_[0])

for i in range(a_H):
    for j in range(a_W):
        if a_[i][j] == '#':
            a_new_new.append(a_[i])
            break
 
for i in list(zip(*a_new_new)):
    print(''.join(i))

Submission status: Accepted

Solution code:
import numpy as np
H,W=map(int,input().split(" "))

def white(a):
    ans=0
    for i in range(len(a)):
        if a[i]=="#":
            ans=1
    return ans

A=[]
for i in range(H):
    gyo=list(input())
    if white(gyo)==1:
        A.append(gyo)

Anum=np.array(A)
ash=Anum.shape[1]
for i in range(ash):
    j=ash-i-1
    if white(Anum[:,j])==0:
        Anum=np.delete(Anum,j,1)

for i in range(Anum.shape[0]):
    moji=""
    for j in range(Anum.shape[1]):
        moji+=Anum[i,j]        
    print(moji)

Submission status: Accepted

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

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

mtrx = []

for i in range(H):
    inputstr = input()
    if '#' in inputstr:
        mtrx.append(list(inputstr))

trv_mtrx = list(map(list, zip(*mtrx)))

new_mtrx = []

for line in trv_mtrx:
    if '#' in line:
        new_mtrx.append(line)

for l in list(map(list,zip(*new_mtrx))):
    print(''.join(l))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 25 18:21:29 2018
ABC107B
@author: maezawa
"""

h, w = list(map(int, input().split()))
lattice = []
for i in range(h):
    hi = input()
    if '#' not in hi:
        continue
    else:
        lattice.append(hi)

#print(*lattice, sep='\n')

hn = len(lattice)
rem = []
for i in range(w):
    flag = 0
    for s in lattice:
        if s[i] == '#':
            flag = 1
            break
    if flag == 0:
        rem.append(i)
        
newlattice = []

for s in lattice:
    for i in reversed(range(w)):
        if i in rem:
            if i == w:
                s = s[:i]
            else:
                s = s[:i]+s[i+1:]
    newlattice.append(s)

for s in newlattice:
    print(s)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
graph = [[0 for _ in range(w)] for _ in range(h)]
ans_graph = []
for i in range(h):
  w_g = input()
  for j in range(w):
    graph[i][j] = w_g[j]

pop_row_list = []
pop_ar_list = []
for i in range(h):
  flag = True
  for j in range(w):
    if graph[i][j] != '.':
      flag = False
  if flag == True:
    pop_row_list.append(i)

for j in range(w):
  flag = True
  for i in range(h):
    if graph[i][j] != '.':
      flag = False
  if flag == True:
    pop_ar_list.append(j)

ans_graph = []

for i in range(h):
  if i in pop_row_list:
    continue
  ans_graph.append([])
  for j in range(w):
    if j in pop_ar_list:
      continue
    ans_graph[-1].append(graph[i][j])

for i in range(len(ans_graph)):
  print("".join(ans_graph[i]))

Submission status: Accepted

Solution code:
import numpy as np

H, W = (int(i) for i in input().split())

A = [["" for i in range(W)] for j in range(H)]

for i in range(H):
    tmp = list(input())
    for j in range(W):
        A[i][j] = tmp[j]

hlist = []
wlist = []

for i in range(H):
    if "#" not in A[i]:
        hlist.append(i)

for j in range(W):
    tmp = []
    for i in range(H):
        tmp.append(A[i][j])
    if "#" not in tmp:
        wlist.append(j)

# print(hlist)
# print(wlist)

for i in hlist:
    for j in range(W):
        A[i][j] = 0

for j in wlist:
    for i in range(H):
        A[i][j] = 0

for i in range(H):
    while True:
        if 0 in A[i]:
            A[i].remove(0)
        else:
            break

while True:
    if [] in A:
        A.remove([])
    else:
        break

for li in A:
    print("".join(li))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [[] for i in range(h)]
for i in range(h):
    a_tmp = input()
    for _ in a_tmp:
        a[i].append(_)
# for i in range(h):
#    print(a[i])
yoko = []
for i in range(h):
    judge = True
    for j in range(w):
        if a[i][j] == "#":
            judge = False
            break
    if judge:
        yoko.append(i)
tate = []
for i in range(w):
    judge = True
    for j in range(h):
        if a[j][i] == "#":
            judge = False
            break
    if judge:
        tate.append(i)
# print(tate)
it = 0
iy = 0
an = [[] for i in range(h-len(yoko))]
# print('sol')
for i in range(h):
    sum = 0
    for j in range(w):
        if i not in yoko and j not in tate:
            print(a[i][j], end="")
            sum += 1
    if sum != 0:
        print("")

Submission status: Accepted

Solution code:
a,b = [int(i) for i in input().split()]

import numpy as np
n = []

for i in range(a):
    buf = list(input())
    if "#" in buf:
        n.append(buf)

buffer = []
for i in range(len(n)):
    for j in range(b):
        if "#" in n[i][j]:
            buffer.append(j)

buffer = list(set(buffer))

for i in range(len(n)):
    joined = [n[i][j] for j in buffer]
    print("".join(joined))

Submission status: Accepted

Solution code:
a,b=map(int,input().split(" "))
l=[]
for i in range(a):
    k=list(input())
    l.append(k)
ca=0
for i in range(a):
    for j in range(b):
        if l[i-ca][j]=="." and j+1==b:
            del l[i-ca]
            ca+=1
        elif l[i-ca][j]=="." :
            pass
        else:
            break
cb=0
for i in range(b):
    for j in range(a-ca):
        if l[j][i-cb]=="." and j+1==a-ca:
            for k in range(a-ca):
                del l[k][i-cb]
            else:
                cb+=1
        elif l[j][i-cb]==".":
            pass
        else:
            break
        
for i in l:
    print(*i,sep="")

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, raw_input().split())
grids = []
for i in xrange(H):
  grids.append(raw_input())
  
grid_num = []
for grid in grids:
  grid_num.append(map(lambda x: 1 if x == '#' else 0, grid))
  
grid_num = np.array(grid_num)

comp_grid_num = []
for w in xrange(W):
  if grid_num[:, w].any():
    comp_grid_num.append(grid_num[:, w])

comp_grid_num = np.array(comp_grid_num)
comp_grid = ""
for h in xrange(H):
  if comp_grid_num[:, h].any():
    comp_grid += "".join(map(lambda x: '#' if x else '.', comp_grid_num[:, h])) + "\n"
    
print comp_grid

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lis = []
for i in range(n):
  lis.append(str(input()))
tate = [0]*n
yoko = [0]*m
for k in range(n):
  for h in range(m):
    if lis[k][h] == "#":
      tate[k] = 1
      yoko[h] = 1
li = []
cou = n
for i in range(n):
  s = []
  for k in range(m):
    if tate[i] != 0 and yoko[k] != 0:s.append(lis[i][k])
  if s == []:
    cou -= 1
  else:
    li.append(s)
for i in range(cou):print("".join(li[i]))

Submission status: Accepted

Solution code:
# coding: utf-8


H, W = map(int,input().split())
moto = []
for i in range(H):
    moto.append(list(input()))
for i in range(H):
    j = 0
    while moto[H-i-1][j] == ".":
        if j == W-1:
            moto.pop(H-i-1)
            break
        j += 1

for i in range(W):
    j = 0
    while moto[j][W-i-1] == ".":
        if j == len(moto)-1:
            for k in range(len(moto)):
                moto[k].pop(W-i-1)
            break
        j += 1
for i in range(len(moto)):
    for j in range(len(moto[0])-1):
        print(moto[i][j],end="")
    print(moto[i][len(moto[0])-1])

Submission status: Accepted

Solution code:
import numpy as np

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

board = []
arr = np.empty((0,W),str)

for i in range(H):
  string = list(str(input()))
  board.append(string)
  arr = np.append(arr, np.array([string]), axis=0)

delete_h = []
delete_w = []
for i in range(H):
  cc = 0
  for j in range(W):
    if board[i][j] == "#":
      cc += 1
  if cc == 0:
    delete_w.append(i)

for i in range(W):
  cc = 0
  for j in range(H):
    if board[j][i] == "#":
      cc += 1
  if cc == 0:
    delete_h.append(i)
    
delete_w.reverse()
delete_h.reverse()

for i in delete_h:
  arr = np.delete(arr, i, 1)

for i in delete_w:
  arr = np.delete(arr, i, 0)

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

Submission status: Accepted

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

del_lst = []
# 横の削除
for i in range(H):
  for j in range(W):
    if a[i][j] == '#':
      break
  else:
    del_lst.append(i)

# 削除
for i in sorted(del_lst,reverse=True):
  a.pop(i)

# 列の削除
del_lst = []
for i in range(len(a[0])):
  for j in range(len(a)):
    if a[j][i] == '#':
      break
  else:
    del_lst.append(i)

# 削除
for i in sorted(del_lst,reverse=True):
  for j in range(len(a)):
    str = list(a[j])
    str.pop(i)
    a[j] = ''.join(str)

for _a in a:
  print(_a)

Submission status: Accepted

Solution code:
import numpy as np

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

A = np.empty((H, W), dtype='str')
for i in range(H):
    A[i, :] = list(input())


def delete_row(A):
    nrow = A.shape[0]
    ncol = A.shape[1]

    idx = []
    for i in range(nrow):
        if (''.join(A[i, :]) != '.'*ncol):
            idx.append(i)
    return(A[idx, :])


def delete_col(A):
    nrow = A.shape[0]
    ncol = A.shape[1]

    idx = []
    for i in range(ncol):
        if (''.join(A[:, i]) != '.'*nrow):
            idx.append(i)
    return(A[:, idx])

while(True):
    nrow, ncol = A.shape
    A = delete_row(A)
    A = delete_col(A)
    nrow_, ncol_ = A.shape
    if (nrow_ == nrow and ncol_ == ncol):
        break

for i in range(A.shape[0]):
    print(''.join(A[i, :]))

Submission status: Accepted

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


def main():
    h, w = list(map(int, input().split()))
    removed = list()

    for i in range(h):
        ai = input()

        if ai.count('.') != w:
            removed.append(ai)

    ans = list()
    count = 0

    for j in range(len(removed[0])):
        is_black = False

        for i in range(len(removed)):
            if removed[i][j] == '#':
                is_black = True

        if is_black:
            for i in range(len(removed)):
                ans.append(removed[i][j])

            count += 1

    for m in range(len(ans) // count):
        result = ''

        for k in range(m, len(ans), len(ans) // count):
            result += ans[k]

        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[]
l=set()
for i in range(h):
  a=list(input())
  if set(a) != set("."):
    s.append(a)
    for j in range(w):
      if a[j]=="#":
        l|={j}
for i in s:
  p=""
  for j in sorted(list(l)):
    p+=i[j]
  print(p)

Submission status: Accepted

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

for _ in range(0, h):
    grid.append(input())

while True:
    modified = False

    for i in range(0, h):
        if all(True if grid[i][j] == "." else False for j in range(0, w)):
            del grid[i]

            modified = True
            h       -= 1

            break

    for j in range(0, w):
        if all(True if grid[i][j] == "." else False for i in range(0, h)):
            for i in range(0, h):
                grid[i] = grid[i][0:j] + grid[i][j + 1:]

            modified = True
            w       -= 1

            break

    if not modified:
        break

for r in grid:
    print(r)

Submission status: Accepted

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

import copy

def check_w(in_l):
    l = copy.deepcopy(in_l)
    for i in range(len(l)):
        line = list(l[i])
        # print(line)
        if '#' not in line:
            # print('del')
            del l[i]
            return l, True
    return l, False


def check_h(in_l):
    l = copy.deepcopy(in_l)
    # 文字数確認
    
    for i in range(len(l[0])):
        line = [ l[j][i:i+1] for j in range(len(l))]
        # print(line)
        if '#' not in line:
            ret = []
            # print(line)
            for j in range(len(l)):
                ret.append(l[j][:i] + l[j][i+1:])
            return ret, True
    return l, False
            
    
def main(in_l):
    l = copy.deepcopy(in_l)
    flg = True
    # print(l)
    
    while flg:
        # print(l)
        ret_l, ret_f = check_w(l)
        if ret_f:
            l = ret_l
            flg = True
            continue
        else:
            flg = False

        ret_l, ret_f = check_h(l)
        if ret_f:
            l = ret_l
            flg = True
            continue
        else:
            flg = False

    # 出力
    for line in l:
        print('{}'.format(line))
    
    
if __name__ == '__main__':
    try:
        h, w = list(map(int,input().strip().split(" ")))
        l = []
        for _ in range(h):
            l.append(input().strip())
        main(l)
    except EOFError:
        pass

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a_list = []
for i in range(H):
    a_list.append(list(map(str, input().split())))
dot = '....................................................................................................'

a_list2 = []
for i in range(H):
    if a_list[i] != [dot[0:W]]:
        a_list2.append([c for c in a_list[i][0]])

a_list3 = []
for i in range(len(a_list2[0])):
    if ''.join(list(np.array(a_list2)[:,i])) != dot[0:len(a_list2)]:
        a_list3.append(list(np.array(a_list2)[:,i]))

for i in range(len(a_list3[0])):
    print(''.join(list(np.array(a_list3).T[i,:])))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
ma = []
s = 0
for i in range(h):
    k = []
    k += input()
    if k.count("#") != 0:
        ma.append(k)
        s += 1
q = []
for i in range(w):
    for j in range(s):
        if ma[j][i] == "#":
            break
    else:
        q.append(i)
for i in range(len(q)):
    for j in range(s):
        del ma[j][q[-(i+1)]]
for i in range(s):
    print("".join(ma[i]))

Submission status: Accepted

Solution code:
import numpy as np

H,W=map(int,input().split())
a=np.zeros((H,W))
for i in range(H):
    tmp = input()
    for j in range(W):
        if tmp[j] == "#":
            a[i][j]=1

tmp=[]
for i in range(H):
    if np.sum(a[i])==0:
        tmp.append(i)
a = np.delete(a,tmp,0)

h=len(tmp)

a = a.T

tmp=[]
for i in range(W):
    if np.sum(a[i])==0:
        tmp.append(i)
a = np.delete(a,tmp,0)
               
a = a.T

w = len(tmp)

ans = list(a)

for i in range(H-h):
    tmp=a[i]
    for j in range(W-w):
        if tmp[j] == 1:
            print("#", end="")
        else:
            print(".", end="")
    print()

Submission status: Accepted

Solution code:
from operator import itemgetter

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

A = []
Hnew = 0
for i in range(H):
    temp = input()
    if temp == '.' * W:
        pass
    else:
        A.append(temp)
        Hnew += 1

FlagA = [0] * W

for i in range(W):
    for j in range(Hnew):
        if A[j][i] == '#':
            FlagA[i] = 1
            break

for i in range(Hnew):
    for j in range(W):
        if FlagA[j] == 1:
            print(A[i][j], end="")
    print()