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=[""]*h
for i in range(h):
    a[i]=input()

row=[0]*h
col=[0]*w

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

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

        print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = []
for i in range(H):
    a = input()
    if a.count("#") >= 1:
        A.append(a)
#print(A)
B = [""]*len(A)
#print(B)
for i in range(len(A[0])):
    b = False
    for j in range(len(A)):
        #print(A[j][i])
        if A[j][i] == "#":
            b = True

    if b == True:
        for j in range(len(A)):
            B[j] += A[j][i]
        #print(1)
    #print("------------")

for k in B:
    print(k)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for _ in range(h):
	b=[]
	s=input()
	for i in range(w):
		b.append(s[i])
	a.append(b)
	
#タテのチェック
for i in range(w):
	tmp=0
	for j in range(h):
		if a[j][i]=="#":
			tmp=1
	if tmp==0:
		for j in range(h):
			a[j][i]="0"

#ヨコのチェック
for i in range(h):
	if not "#" in a[i][:]:
		a[i][:]=[0]*w

for i in range(h):
	tmpl=[]
	for j in range(w):
		if not a[i][j]=="0":
			tmpl.append(a[i][j])
	if "#" in tmpl or "." in tmpl:
		print("".join(tmpl))		#listを詰めて表示

Submission status: Accepted

Solution code:
inf = 10 ** 15
mod = 10 ** 9 + 7
h,w = map(int, input().split())
maps = [input() for i in range(h)]
remh = []
remw = []
for i in range(h):
    flag = True
    for j in range(w):
        if maps[i][j] == '#':
            flag = False
            break
    if not flag:
        remh.append(i)
for j in range(w):
    flag = True
    for i in range(h):
        if maps[i][j] == '#':
            flag = False
    if not flag:
        remw.append(j)

for num in remh:
    a = []
    for tmp in remw:
        a.append(maps[num][tmp])
    s = ''.join(a)
    print(s)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
alist=[]
numans=list(range(h))
for i in range(h):
    a=list(input())
    alist.append(a)
for i in range(h):
    if alist[h-i-1].count(".")==w:
        numans.remove(h-i-1)
lena=len(alist)
yn=0
for i in range(w):
    for j in range(lena):
        if alist[j][w-i-1]!=".":
            yn=1
    if yn==0:
        for j in range(lena):
            del alist[j][w-i-1]
    yn=0
c=""
lena=len(alist[0])
for i in numans:
    for j in range(lena):
        c+=alist[i][j]
    print(c)
    c=""

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
    a[i] = 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()

Submission status: Accepted

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

rows = [input() for _ in range(H)]
rows = [row for row in rows if '#' in row]
cols = list(zip(*rows))
cols = [col for col in cols if '#' in col]
rows = list(zip(*cols))

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
A = [sr() for _ in range(H)]
B = []
for a in A:
    if '#' in a:
        B.append(a)

B = zip(*[b for b in zip(*B) if '#' in b])
for b in B:
    print(*b, sep='')

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
B = np.array([list(sr()) for _ in range(H)])
A = [[1 if x == '#' else 0 for x in b] for b in B]
row = np.sum(A, axis=1)
column = np.sum(A, axis=0)
r = row != 0
c = column != 0
answer = B[r]
answer = answer[:, c].tolist()
for a in answer:
    print(''.join(a))

Submission status: Accepted

Solution code:
def rotate_matriz(s, x, y):
    ex = [[""] * x for _ in range(y)]
    for i in range(x):
        for j in range(y):
            ex[j][i] = s[i][j]
    return ex


def pprint(s, n):
    for i in range(n):
        print("".join(s[i]))


def check(s, n):
    ex = []
    ct = 0
    for i in range(n):
        if "#" in s[i]:
            ex.append(s[i][:])
        else:
            ct += 1
    return ex, n - ct


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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
count = 0
for i in range(H):
    tmp = input() #入力は一文字として入ってくる
    if tmp == '.' * W:
        count += 1
    else:
        A.append(tmp)

skipp = []
for j in range(W):
    coucou = 0
    for i in range(H - count):
        if A[i][j] == '#':
            coucou = 1
            break
    if coucou == 0:
        skipp.append(j)
        
#出力
for i in range(H-count):
    for j in range(W):
        if j not in skipp:
            print(A[i][j], end = '')
    print()

Submission status: Accepted

Solution code:
from functools import reduce

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

A = []
is_colm_black = [True] * W
for _ in range(H):
    a = list(input())
    if DEBUG:
        print("a: {}".format(a))
    if not reduce(lambda x, y: x and (y == "."), a, True):
        A.append(a)
        for i, j in enumerate(a):
            is_colm_black[i] &= (j == '.')

if DEBUG:
    print("A: {}".format(A))
    print("is_colm_black: {}".format(is_colm_black))

ans = []
for i in range(len(A)):
    a = ""
    for j, f in enumerate(is_colm_black):
        if not f:
            a += A[i][j]
    if a:
        ans.append(a)
    if DEBUG:
        print("i: {}, a: {}".format(i, a))
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    h,w=map(int, input().split())
    l=[]
    for i in range(h):
        ll=list(input())
        l.append(ll)
    # lはl[列番号][行番号]になってる
    # 行と列のチェックリストを作る。行が縦で列が横
    gyou= [False] * w
    retu= [False] * h
    # 列番号をずらしていく
    for retunum in range(h):
        # 行番号をずらしていく
        for gyounum in range(w):
            # 同じ行or列に１個でも'#'があればその時点でその行or列は消えない
            # '#'があった列と行をTrueにしていく
            if l[retunum][gyounum]=='#':
                retu[retunum]=True
                gyou[gyounum]=True
    # 列も行もTrue→行と列の両方のどこかに'#'があるから、行と列の交点のマスは消えない
    for retunum in range(h):
        if retu[retunum]:
            for gyounum in range(w):
                if gyou[gyounum]:
                    # 同じ列の出力が終わるまでは改行しない
                    print(l[retunum][gyounum],end='')
            # １個の列が終わったら改行
            print('')
resolve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    h,w=map(int, input().split())
    l=[]
    for i in range(h):
        ll=list(input())
        l.append(ll)
    # 行と列のチェックリストを作る。gyou[0]は0行目を示す
    gyou= [False] * w
    retu= [False] * h
    for jretu in range(h):
        for kgyou in range(w):
            # 同じ行or列に１個でも'#'があればその時点でその行or列は消えない
            # '#'があった列と行をTrueにしていく
            if l[jretu][kgyou]=='#':
                retu[jretu]=True
                gyou[kgyou]=True
    for jretu in range(h):
        if retu[jretu]:
            for kgyou in range(w):
                if gyou[kgyou]:
                    print(l[jretu][kgyou],end='')
            print('')
resolve()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
maze = []
for _ in range(h):
  s = input()
  if s != '.'*w:
    maze.append(s)
h = len(maze)
skip = []
for j in range(w):
  for i in range(h):
    if maze[i][j] == '#':
      break
  else:
    skip.append(j)
 
for i in range(h):
  for j in range(w):
    if j not in skip:
      print(maze[i][j],end= '')
  print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
maze = []
for _ in range(h):
  s = input()
  if s != '.'*w:
    maze.append(s)
h = len(maze)
skip = []
for j in range(w):
  for i in range(h):
    if maze[i][j] == '#':
      break
  else:
    skip.append(j)

for i in range(h):
  for j in range(w):
    if j not in skip:
      print(maze[i][j],end= '')
  print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
graph = [list(input()) for _ in range(H)]
def rotate_cw(graph):
    height = len(graph)
    width = len(graph[0])
    result = [[] for _ in range(width)]
    for x in range(width):
        for y in range(height - 1, -1, -1):
            result[x].append(graph[y][x])
    return result

for _ in range(max(H, W)):
    for angle in range(4):
        pop = 0
        for i in range(len(graph)):
            if "#" not in graph[i-pop]:
                graph.pop(i-pop)
                pop += 1
        graph = rotate_cw(graph)
for line in graph:
    print("".join(line))

Submission status: Accepted

Solution code:
import numpy as np
h,w = map(int,input().split())
graph = [['.' for j in range(w)]for i in range(h)]


for i in range(h):
    tmp = input()
    for j in range(len(tmp)):
        graph[i][j] = tmp[j]
graph = np.array(graph)

flag = True
while flag:
    flag = False
    for i in range(graph.shape[1]):
        if( graph[:,i] == ['.']*graph.shape[0]).all():
            flag = True
            if i == 0:
                graph = graph[: , 1:]
                break
                
            if i == graph.shape[1] -1:
                graph = graph[:,:i]
                break
                
            else:
                graph = np.concatenate([graph[:,:i],graph[:,i+1:] ], 1)
                break
                
    for i in range(graph.shape[0]):
        if (graph[i,:] == ['.']*graph.shape[1]).all():
            flag = True
            if i == 0:
                graph = graph[1: , :]
                break
                
            if i == graph.shape[0] -1:
                graph = graph[:i,:]
                break
                
            else:
                graph = np.concatenate([graph[:i , :],graph[i+1: , :] ], 0)
                break
                
for i in graph:
    print(*i, sep="")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [input() for i in range(h)]
w_row = []
w_column = []
for i in range(h):
  black = False
  for j in range(w):
    if a[i][j] == '#':
      black = True
      break
  if not black:
    w_row.append(i)
for i in range(w):
  black = False
  for j in range(h):
    if a[j][i] == '#':
      black = True
      break
  if not black:
    w_column.append(i)
for i in range(h):
  if i in w_row:
    continue
  s = ''
  for j in range(w):
    if j in w_column:
      continue
    s += a[i][j]
  print(s)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
H, W = map(int, input().split())
L = []
for i in range(H):
    L.append(input())
cl = L[:]

al = []
for i in cl:
    if ('#' in i):
        al.append(i)

if (len(al) == 0):
    print()
    exit()

for i in range(W):
    d[i] = True

for i, v in enumerate(al):
    for k, j in enumerate(v):
        if (j == '.'):
            continue
        else:
            d[k] = False
for i, v in d.items():
    if (v):
        for j, k in enumerate(al):
            if (i == 0):
                al[j] = ' ' + k[1:]
            elif ((i == W - 1) and (W != 1)):
                al[j] = k[:i] + ' '
            else:
                al[j] = k[:i] + ' ' + k[i + 1:]
for i in al:
    print(i.replace(' ', ''))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
fi = [input() for _ in range(h)]
row = [False]*h
col = [False]*w
for i in range(h):
    for j in range(w):
        if fi[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(fi[i][j],end='')
        print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    k=input()
    if k!="."*w:
        a.append(k)
l=len(a)
#print(a)
ans=[[] for i in range(l)]
for i in range(w):
    for j in range(l):
        if a[j][i]=="#":
            for k in range(l):
                ans[k].append(a[k][i])
            break
for i in range(l):
    print("".join(ans[i]))

Submission status: Accepted

Solution code:
H, W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]
NA = []
for a in A:
    if '#' in a:
        NA.append(a)
for i in range(W):
    ydel = True
    for j in NA:
        if j[i] == '#':
            ydel = False
            break
    if not ydel:
        continue
    for j in NA:
        j[i] = 'D'
for na in NA:
    nna = []
    for i in na:
        if i != 'D':
            nna.append(i)
    print(''.join(nna))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
print(*map(lambda l: "".join(l), zip(*[column for column in zip(*[row for row in [input() for _ in range(H)] if "#" in row]) if "#" in column])), sep="\n")

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
A = []
for _ in range(H):
    row = input()
    if row != "." * W:
        A.append(list(row))
A = np.array(A, dtype=str)
B = []
for c in range(W):
    if any(map(lambda c: c == "#", A[:, c])):
        B.append(A[:, c])
for row in np.asarray(B).T:
    print("".join(row))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
map_input = [[1 if j=='#' else 0 for j in list(input())] for i in range(h)]

h_li = [0]*h
w_li = [0]*w

for i in range(h):
    for j in range(w):
        h_li[i]+=map_input[i][j]
        w_li[j]+=map_input[i][j]

for i in range(h):
    if h_li[i]==0:
        continue
    tmp=[]
    for j in range(w):
        if w_li[j]==0:
            continue
        tmp.append(map_input[i][j])
    print(''.join(['.' if k==0 else '#' for k in tmp]))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = list()
for _ 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()

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
ss = []
for _ in range(h):
    s = input().strip()
    if '#' in s:
        ss.append(s)
new_h = len(ss)
dels = []
for i in range(w):
    rep = True
    for j in range(new_h):
        if ss[j][i] == '#':
            rep = False
    if rep:
        dels.append(i)
for i in range(new_h):
    now = ss[i]
    pri = []
    for j in range(w):
        if j not in dels:
            pri.append(now[j])
    print(''.join(pri))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    h, w = mi()
    L = [li() for _ in range(h)]
    L_t = [col for col in zip(*L)]
    
    # print('')
    # for line in L:
    #     print(*line)
    # print('')
    # for line in L_t:
    #     print(*line)
    # print('')

    i_strip = set()
    j_strip = set()
    for i in range(h):
        if all(map(lambda x: x == '.', L[i])):
            i_strip.add(i)
    for j in range(w):
        if all(map(lambda x: x == '.', L_t[j])):
            j_strip.add(j)
    # print(i_strip)
    # print(j_strip)
    for i in range(h):
        if i not in i_strip:
            for j in range(w):
                if j not in j_strip:
                    print(L[i][j], end='')
            print('')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
z = []
x = list(map(int, input().split()))
s = [list(input()) for i in range(x[0])]
h = x[0]
w = x[1]
l = []
y = []
# 横
for i in range(0, h):
  for j in range(0, w):
    if s[i][j] == '#':
      y.append(s[i])
      break

t = []
# 縦
# 縦横逆にする
for j in range(0, len(y[0])):
  for i in range(0, len(y)):
    l.append(y[i][j])
  t.append(l)
  l = []

p = []
for i in range(0, len(t)):
  for j in range(0, len(t[i])):
    if t[i][j] == '#':
      p.append(t[i])
      break
u = []
for j in range(0, len(p[0])):
  for i in range(0, len(p)):
    l.append(p[i][j])
  u.append(l)
  l = []
for i in u:
  print(''.join(i))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
skip_w = []
for i in range(w):
    cnt = 0
    for j in range(h):
        if a[j][i] == '.':
            cnt += 1
    if cnt == h:
        skip_w.append(i)
for i in range(h):
    if a[i] == '.'*w:
        continue
    else:
        for j in range(w):
            if j not in skip_w:
                print(a[i][j], end='')
        print()

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
flg = 0
a = []
for i in range(h):
  s = input()
  if '#' in s:
    a.append(s)
  else:
    flg += 1
h -= flg
res = ['']*h
for i in range(w):
  flg = 0
  for j in range(h):
    if a[j][i] == '#':
      flg = 1
  if flg == 1:
    for j in range(h):
      res[j] += a[j][i]
for i in range(h):
  print(res[i])

Submission status: Accepted

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

MAP = [list(input()) for i in range(H)]
check = ['.' for j in range(W)]
MAP_h = []
MAP_T = []

for i in range(H):
    if check != MAP[i]:
        MAP_h.append(MAP[i])
   
check = ['.' for k in range(len(MAP_h))]   

for i in range(W):
    tmp = [row[i] for row in MAP_h]
    if tmp != check:
        MAP_T.append(tmp)

MAP= map(list, zip(*MAP_T))

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

Submission status: Accepted

Solution code:
h, w = [int(x) for x in input().split()]
 
temp_list = []
flag = [False] * w
for _ in range(h):
    a = input()
    if "#" not in a:
        continue
    temp_list.append(a)
    for i in range(w):
        flag[i] = flag[i] or a[i] == "#"

for temp in temp_list:
    print("".join([temp[i] for i in range(w) if flag[i]]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

f = []

for i in range(h):
    f.append(list(input()))
    
a = []
    
for i in range(len(f)):
    if f[i] == ["."]*len(f[i]):
        a.append(i)
        
for i in a:
    del f[i]
    for s in range(len(a)):
        a[s] -= 1
        
f2 = []

for i in range(w):
    s = []
    
    for k in f:
        s.append(k[i])
        
    f2.append(s)
    
b = []
    
for i in range(len(f2)):
    if f2[i] == ["."]*len(f2[i]):
        b.append(i)
        
for i in b:
    del f2[i]
    for s in range(len(b)):
        b[s] -= 1
        
ff = []

for i in range(len(f2[0])):
    s = []
    
    for k in f2:
        s.append(k[i])
        
    ff.append(s)
        
for i in ff:
    for s in range(len(i)-1):
        print(i[s],end = "")
    
    print(i[-1])

Submission status: Accepted

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

while True:
  ans = 0
  for h in range(H):
    if list(set(S[h]))[0] == ".":
      S.pop(h)
      H -= 1
      ans = 1
      #print(S)
      #print()
      break
  for w in range(W):
    #print([S[h][w] for h in range(H)])
    if list(set([S[h][w] for h in range(H)]))[0] == ".":
      for h in range(H):
        S[h].pop(w)
      W -= 1
      ans = 1
      #print(S)
      #print()
      break
  if ans == 0:
    break

for h in range(H):
  print("".join(S[h]))

Submission status: Accepted

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

b_rows = []
for row in range(H):
    if field[row].count(".") != W:
        b_rows.append(row)

b_columns = []
for column in range(W):
    memo = []
    for row in range(H):
        memo.append(field[row][column])
    if memo.count(".") != H:
        b_columns.append(column)

for i in b_rows:
    for j in b_columns:
        print(field[i][j], end="")
    print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[list(input())for i in range(H)]
ww=set()
hh=set()
for h in range(H):
  for w in range(W):
    if A[h][w]=='#':
      ww.add(w)
      hh.add(h)
ww=sorted(list(ww))
for h in sorted(list(hh)):
  _=''
  for w in ww:
    _+=A[h][w]
  print(_)

Submission status: Accepted

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

for i in range(h-1, -1, -1):
    if a[i] == r:
        del(a[i])

h = len(a)
for i in range(w-1, -1, -1):
    allw = True
    for j in range(h):
        if a[j][i] != '.':
            allw = False
    if allw:
        for j in range(h):
            del(a[j][i])

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

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
t = []
Hcut = []
Wcut = []
count = 0
for i in range(H):
  t.append(input())
  
#削除するべき行の検出  
for i in range(H):
  for j in range(W):
    if t[i][j] == "#":
      count += 1
      break
  if count == 0:
    Hcut.append(i)
  count = 0
  
#削除するべき列の検出
for i in range(W):
  for j in range(H):
    if t[j][i] == "#":
      count += 1
      break
  if count == 0:
    Wcut.append(i)
  count = 0

#出力
for i in range(H):
  judge = 0
  for j in range(W):
    if i in Hcut or j in Wcut:
      continue
    else:
      print(t[i][j],end="")
      judge = 1
  if judge == 1:
    print()

Submission status: Accepted

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

emp_row = [False] * H
emp_col = [False] * W

for i in range(H):
  isEmp = True
  for j in range(W):
    if A[i][j] == "#":
      isEmp = False
      break
  emp_row[i] = isEmp
  
for i in range(W):
  isEmp = True
  for j in range(H):
    if A[j][i] == "#":
      isEmp = False
  emp_col[i] = isEmp
  
ANS = []
for i in range(H):
  if emp_row[i]:
    continue
  row = []
  for j in range(W):
    if emp_col[j]:
      continue
    row.append(A[i][j])
  ANS.append(row)
  
for a in ANS:
  print("".join(a))

Submission status: Accepted

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

for i in range(H):
  line = input()
  if line != '.' * W:
    G.append(line)

H = len(G)
ans = []

for i in range(W):
  flg = False
  tmp = ''
  for j in range(H):
    if G[j][i] == '.':
      flg = False
    else:
      flg = True
    tmp += G[j][i]
  if tmp != '.' * H:
    ans.append(tmp)

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
X = []
res = []
F = [True] * W

for i in range(H):
  x = list(input())
   
  if x.count("#") != 0:
    X.append(x)

  for j in range(W):
    if x[j] == "#":
      F[j] = False

for k in range(len(X)):
  r = ""
  for l in range(W):
    if not F[l]:
      r += (X[k][l])
  print(r)

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
np_a=np.array(a)
np_at=np_a.T
at=np_at.tolist()

r=[]
c=[]

for i in range(h):
    if a[i].count('#')==0:
        r.append(i)
for i in range(w):
    if at[i].count('#')==0:
        c.append(i)

for i in range(len(r)):
    del a[r[i]-i]
for j in range(len(c)):
    for i in range(h-len(r)):
        del a[i][c[j]-j]

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

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
ar = []
for _ in range(h):
  row = list(input())
  if row == ['.']*w:
    continue
  ar.append(row)

c = 0
while c < len(ar[0]):
  count = 0
  for r in range(len(ar)):
    if ar[r][c] == '#':
      count += 1
  if count == 0:
    for row in ar:
      row.pop(c)
  else:
    c += 1

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

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
H, W = ri_()
a = [[i for i in rs()] for _ in range(H)]
a = [i for i in a if i.count('#') > 0]
a = list(zip(*a))
a = [i for i in a if i.count('#') > 0]
a = list(zip(*a))
a = [''.join(i) for i in a]
for ai in a:
    print(ai)

Submission status: Accepted

Solution code:
import numpy as np

h, w = list(map(int, input().split()))
A = np.array([list(input()) for i in range(h)])

D = A[A == "."]

while True:

    B = A[np.any(A != ".", axis= 1)]
    B = B[:, np.any(A != ".", axis = 0)]

    if np.array_equal(A, B) == True:
        break
    else:
        A = B 

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

Submission status: Accepted

Solution code:
A,B=[],[]
h,w=map(int,input().split())
for i in range(h):
    a=input()
    if "#" in a:
        A.append(a)
b=""
for i in range(w):
    if "#" not in b:
        B.append(i-1)
    b=""
    for j in range(len(A)):
        b+=A[j][i]
if "#" not in b:
    B.append(w-1)
B.pop(0)
o=0
for i in range(len(A)):
    o=0
    A[i]=list(A[i])
    for j in B:
        A[i].pop(j-o)
        if o==len(B)-1:
            print("".join(A[i]))
        o+=1
if len(B)==0:
    for i in A:
        print("".join(i))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
H = []
l = []
for i in range(h):
  k = list(input())
  if len(set(k)) == 1 and k[0] == '.':
    H.append(i)
  l.append(k)
W = []
for j in range(w):
  flag = True
  x = l[0][j]
  if x == '.':
    for k in l:
      if k[j] != x:
        flag = False
    if flag:
      W.append(j)
for i in H: 
  for j in range(w):
    l[i][j] = ''
for j in W:
  for i in range(h):
    l[i][j] = ''
for k in l:
  if ''.join(k) != '':
    print(''.join(k))