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:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

h,w = MI()
a = LS(h)

# pprint(a)

rc = []
rr = []

for i in range(h):
    r = a[i]
    if r == ['.']*len(a[0]):
        rr.append(i)
# print(rr)

na = []
for i in range(h):
    if i not in rr:
        na.append(a[i])
# pprint(na)

for i in range(w):
    c = mycol(na,i)
    if c == ['.']*len(na):
        rc.append(i)
# print(rc)

ans = []
for i in range(len(na)):
    row = na[i]
    new_row = []
    for j in range(len(na[0])):
        if j not in rc:
            new_row.append(row[j])
    ans.append(new_row)
# pprint(ans)

for i in range(len(ans)):
    myoutput(ans[i],space=False)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[input() for _ in range(H)]
answers1=[]
for h in range(H):
    a1=a[h]
    if '#' in a1:
        answers1.append(a1)
answers2=['' for _ in range(len(answers1[0]))]
for answer in answers1:
    for n in range(len(answer)):
        answers2[n]+=answer[n]
answers=[]
for answer in answers2:
    if '#' in answer:
        answers.append(answer)
for x in range(len(answers[0])):
    kotae=''
    for y in range(len(answers)):
        kotae+=answers[y][x]
    print(kotae)

Submission status: Accepted

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

for i in range(h):
    row = list(input())
    if row != ["."]*w:
        cell.append(row)

counter = []
for i in range(w):
    flag = 0
    for j in range(len(cell)):
        if cell[j][i] == "#":
            flag = 1
            break
    if flag == 1:
            counter.append(i)

for a in cell:
    ans = ''
    for i in counter:
        ans = ans + a[i]
    print(ans)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [input() for i in range(H)]
b = [0] * W
c = [0] * H
for i in range(H):
    cnt = 0
    for j in range(W):
        if a[i][j] == '#':
            b[j] += 1
            cnt += 1
    c[i] = cnt 

for i in range(H):
    if c[i]==0:
        continue
    for j in range(W):
        if b[j]!=0:
            print(a[i][j],end='')
    print()

Submission status: Accepted

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

grid = []
for _ in range(h):
    x = input()
    if x.count(".") != len(x):
        grid.append(x)

grid = list(map(list, zip(*grid)))

grid_t = []
for g in grid:
    if g.count(".") != len(g):
        grid_t.append(g)

ans = list(map(list, zip(*grid_t)))

for a in ans:
    print("".join(a))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
s = 0
li = []
lire = []
linew = []
for i in range(h):
    li.append(input())
for i in range(w):
    for j in range(h):
        if li[j][i] == ".":
            s = 1
        else:
            s = 0
            break
    if s == 1:
        lire.append(i)
        s = 0
for i in range(h):
    a = ""
    for j in range(w):
        if j not in lire:
            a += li[i][j]
    linew.append(a)
for i in range(len(linew)):
    if "#" not in linew[i]:
        continue
    else:
        print(linew[i])

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[]
ans=[]
for i in range(h):
    A.append(list(input()))
for a in A:
    if a != ['.']*w:
        ans.append(a)
counter=[]
for i in range(w):
    flag=0
    for j in range(len(ans)):
        if ans[j][i]=='#':
            flag=1
            break
    if flag==1:
        counter.append(i)
        
for a in ans:
    temp=''
    for i in counter:
        temp+=a[i]
    print(temp)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[]
ans=[]
for i in range(h):
  A.append(list(input()))
for a in A:
  if a != ['.']*w:
    ans.append(a)
counter=[]
for i in range(w):
  flag=0
  for j in range(len(ans)):
    if ans[j][i]=='#':
      flag=1
      break
  if flag==1:
    counter.append(i)

for a in ans:
  tmp=''
  for i in counter:
    tmp=tmp+a[i]
  print(tmp)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ls = []
for i in range(N):
    ls.append(list(input()))
yoko = []
tate = [i for i in range(M)]
for i in range(N):
    if ls[i].count('.') == M:
        yoko.append(i)
for i in range(N):
    for j in range(M):
        if ls[i][j] == '#' and j in tate:
            tate.remove(j)
tate2 = list(range(M))
for i in range(M):
    if i in tate:
        tate2.remove(i)

ansls = []
for i in range(N):
    if not i in yoko:
        ansls.append([ls[i][j] for j in tate2])
for i in ansls:
    print(''.join(i))

Submission status: Accepted

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

hl=[]
wl=[]

for i in range(h):
    if a[i]=="."*w:
        hl +=[i]
for i in range(w):
    if all([a[j][i]=="." for j in range(h)]):
        wl += [i]


for i in range(h):
    if i not in hl:
        for j in range(w):
            if j not in wl:
                print(a[i][j],end="")
        else:
            print("")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
L=[[] for i in range(H)]
yoko=list()
for i in range(H):
  L1=list(input())
  if L1==["."]*W:
    yoko.append(i)
  L[i]=L1
R=list(range(W))
for i in range(H):
  for j in range(W):
    if j in R and L[i][j]=="#":
      R.remove(j)
for i in range(H):
  if i in yoko:
    continue
  s=L[i]
  r=list()
  for j in range(W):
    if j not in R:
      r.append(s[j])
  print("".join(r))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    y = input()
    if "#" in y:
        a.append(y)
#print(a)
#print(len(a))
ans = [""] * len(a)
for i in range(len(a[0])):
    flag = 0
    for j in range(len(a)):
        if a[j][i] == "#":
            flag = 1
    if flag == 1:
        for j in range(len(a)):
            ans[j] += a[j][i]
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

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

tmp_h = [int(0) for i in range(h)]
tmp_w = [int(0) for j in range(w)]
for i in range(h):
    for j in range(w):
        if masu[i][j]=='.':
            tmp_h[i] += 1
            tmp_w[j] += 1
#print(tmp_h)
#print(tmp_w)

ans = []
for i in range(len(tmp_h)):
    if tmp_h[i] != w:
        tmp = ''
        for j in range(w):
            if tmp_w[j] != h:
                tmp += masu[i][j]
        ans.append(tmp)

#for i in range(h):
#    print(masu[i])
#print('-----')
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    x = input()
    if x.count('#') == 0:
        continue
    A.append(x)

c = set()
for a in A:
    for i in range(W):
        if a[i] == '#':
            c.add(i)

for a in A:
    for i in range(W):
        if i in c:
            print(a[i], end='')
    print()

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            H[i] += 1
            W[j] += 1

for i in range(h):
    if H[i] != 0:
        for j in range(w):
            if W[j] != 0:
                print(a[i][j], end = '')
        print()

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())
a = []
for i in range(h):
    line = input()
    if line != "." * w:
        a.append(list(line))

h = len(a)

w_pass =[]
for i in range(w):
    for j in range(h):
        if a[j][i] != ".":
            break
    else:
        w_pass.append(i)

for i in range(h):
    line = ""
    for j in range(w):
        if j in w_pass:
            pass
        else:
            line += a[i][j]
    print(line)

Submission status: Accepted

Solution code:
import math

h, w = map(int, input().split(" "))
aL = [list(input()) for _ in range(h)]

for i in reversed(range(h)):
    if len(set(aL[i])) == 1 and aL[i][0][0] == ".":
        del aL[i]

for i in reversed(range(w)):
    for j in range(len(aL)):
        if aL[j][i] == "#":
            break
    else:
        for k in range(len(aL)):
            del aL[k][i]

for a in aL:
    print("".join(a))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
for i in range(H):
    if a[i].count('#') > 0:
        s = ''
        for j in range(W):
            if [A[j] for A in a].count('#') > 0:
                s += a[i][j]
        print(s)

Submission status: Accepted

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

for i in range(h):
    line = list(input())
    if line != ["."] * w:
        masu.append(line)

h = len(masu)
del_i = []
for i in range(w):
    for j in range(h):
        if masu[j][i] != ".":
            break
    else:
        del_i.append(i)
w = len(del_i)
for j in range(w):
    for i in range(h):
        masu[i].pop(del_i[j] - j)

for i in range(h):
    print("".join(masu[i]))

Submission status: Accepted

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

Submission status: Accepted

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

board=[]
for i in range(H):
  board_=list(input())
  board.append(board_)

for i in range(H):
  if all([board[i][j]  == '*' or board[i][j]  == '.' for j in range(W)]):
    board[i]=['*']*W

for j in range(W):
  if all([board[i][j] =='*' or board[i][j] =='.' for i in range(H) ]):
    for k in range(H):
      board[k][j]='*'

Board=[[] for i in range(H)]
for i in range(H):
  for j in range(W):
    if board[i][j]!='*':
      Board[i].append(board[i][j])

for i in range(H):
  if Board[i]!=[]:
    print(''.join(Board[i]))
    
  else:
    continue

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [input() for i in range(h)]
a2=[i for i in a if '#' in i]
a3=[i for i in zip(*a2) if '#' in i]
for i in zip(*a3):
    print("".join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
tate=[False]*h
yoko=[False]*w
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            tate[i]=True
            yoko[j]=True
for i in range(h):
    if tate[i]:
        for j in range(w):
            if yoko[j]:
                print(l[i][j],end="")
        print()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

h, w = inm()
grid = []
for i in range(h):
    s = ins()
    if "#" in s:
        grid.append(list(s))
remove = []
for i in range(w):
    tmp = True
    for x in grid:
        if x[i] == "#":
            tmp = False
            break
    if tmp:
        remove.append(i)
for i in remove[::-1]:
    for x in grid:
        x.pop(i)
for i in grid:
    print("".join(i))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    G = [readline().strip() for _ in range(H)]

    row = [False] * H
    col = [False] * W

    for i in range(H):
        for j in range(W):
            if G[i][j] == '#':
                row[i] = col[j] = True

    for i in range(H):
        if not row[i]:
            continue
        for j in range(W):
            if col[j]:
                print(G[i][j], end='')
        print('')

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    G = [readline().strip() for _ in range(H)]

    G = [row for row in G if row != '.' * W]
    G = list(''.join(row) for row in zip(*G))
    G = [row for row in G if row != '.' * len(row)]
    G = list(''.join(row) for row in zip(*G))

    print(*G, sep='\n')

    return


if __name__ == '__main__':
    main()

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()

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())

pic = []
for i in range(H):
    a = list(input())
    if a != ["." for i in range(W)]:
        pic.append(a)

H = len(pic)
        
delete = [0 for i in range(W)]
for i in range(W):
    white = 0
    for j in range(H):
        if pic[j][i] == ".":
            white += 1
        if white == H:
            delete[i] += 1

for i in reversed(range(W)):
    if delete[i] == 1:
        for j in range(H):
            pic[j] = pic[j][0:i] + pic[j][i+1:]

for i in range(H):
    print(*pic[i], sep="")

Submission status: Accepted

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

h = {i: False for i in range(H)}
w = {i: False for i in range(W)}

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            h[i] = True
            w[j] = True

for i in range(H):
    s = ""
    for j in range(W):
        if h[i] and w[j]:
            s += A[i][j]

    if s != "":
        print(s)

Submission status: Accepted

Solution code:
import sys
import numpy as np


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    h, w = nm()
    A = np.array([list(ns()) for _ in range(h)])
    i = 0
    while i < len(A):
        if np.all(A[i] == '.'):
            A = np.delete(A, i, 0)
        else:
            i += 1

    j = 0
    while j < len(A[0]):
        if np.all(A[:, j] == '.'):
            A = np.delete(A, j, 1)
        else:
            j += 1
    for a in A:
        print(''.join(a))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

tate = [False] * H
yoko = [False] * W

for h in range(H):
    for w in range(W):
        if HW_list[h][w] == '#':
            tate[h] = True
            yoko[w] = True

for h in range(H):
    tmp = ''
    for w in range(W):
        if tate[h] and yoko[w]:
            tmp += HW_list[h][w]
    if tmp == '':
        continue
    print(tmp)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
L = []
for i in range(a):
    l = input()
    if not l.count('.') == b:
        L.append(l)

M = []
for i in range(b):
    l = list(map(lambda x: x[i], L))
    if not l.count('.') == len(l):
        M.append(l)

for i in range(len(M[0])):
    for m in M:
        print(m[i],end='')
    print()

Submission status: Accepted

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

for i in range(h):
    ls = input()
    if ls.count(".") == w:
        h_remove.append(i)
    k.append(ls)

for i in range(w):
    xx = ""
    for j in range(h):
        xx += k[j][i]
    if xx.count(".") == h:
        w_remove.append(i)

h_remove = set(h_remove)
w_remove = set(w_remove)
for i in range(h):
    ret = ""
    if i in  h_remove:
        continue
    else:
        for j in range(w):
            if j in w_remove:
                continue
            else:
                ret += k[i][j]
        print(ret)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
m = [[] for _ in range(h)]
x = [False] * h
y = [False] * w
for i in range(h):
    m[i] = list(input())
    if "#" in m[i]:
        x[i] = True
zm = list(zip(*m))
for i, j in enumerate(zm):
    if "#" in j:
        y[i] = True
M = []
for i, H in enumerate(x):
    for v, W in enumerate(y):
        if H and W:
            M.append(m[i][v])
    if M:
        print("".join(M))
    M = []

Submission status: Accepted

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

x = []
for _ in range(H):
    a = [c for c in input()]
    if '#' in a:
        x.append(a)

ans = []
for a in list(zip(*x)):
    if '#' in a:
        ans.append(a)

for a in list(zip(*ans)):
    print(''.join(a))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for _ in range(H):
    row = [{'.': 0, '#': 1}[c] for c in input()]
    if 0 < sum(row):
        A.append(row)
for x in range(W - 1, -1, -1):
    if sum(A[i][x] for i in range(len(A))) == 0:
        for y in range(len(A)):
            A[y][x:x + 1] = []
for row in A:
    print(''.join(['.' if v == 0 else '#' for v in row]))

Submission status: Accepted

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

tmp = copy.deepcopy(HW_list)
h_index = 0
for i, HW in enumerate(HW_list):
    is_all_shiro = True
    for hw in HW:
        if hw == '#':
            is_all_shiro = False
            h_index += 1
            break
    if is_all_shiro:
        tmp.pop(h_index)
w_index = 0
ans = copy.deepcopy(tmp)
for w in range(W):
    is_all_shiro = True
    for t in tmp:
        if t[w] == '#':
            is_all_shiro = False
            w_index += 1
            break
    if is_all_shiro:
        for a in ans:
            a.pop(w_index)
for A in ans:
    print(''.join(A))

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

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

y = [False] * h
x = [False] * w

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

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [set(), set()]
for i in range(h):
    f = True
    for j in range(w):
        f &= (a[i][j] == ".")
    if f:
        s[0].add(i)

for i in range(w):
    f = True
    for j in range(h):
        f &= (a[j][i] == ".")
    if f:
        s[1].add(i)

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

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

c, l = [], []
for i in range(h):
    flag = True
    for j in range(w):
        if a[i][j] != '.':
            flag = False
            break
    if not flag:
        l.append(i)

for i in range(w):
    flag = True
    for j in range(h):
        if a[j][i] != '.':
            flag = False
            break
    if not flag:
        c.append(i)

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

Submission status: Accepted

Solution code:
#全然わからず完コピ
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]
h=[]
for i in range(H):
  if a[i]==['.']*W:
    h.append(i)

w=[]
for i in range(W):
  flag=0
  for j in range(H):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w.append(i)
  
ans=[]
for i in range(H):
  if i not in h:
    r=[]
    for j in range(W):
      if j not in w:
        r.append(a[i][j])
    ans.append(r)

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

Submission status: Accepted

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

w=[]
for i in range(W):
  flag=0
  for j in range(H):
    if a[j][i]=='#':
      flag=1
      break
  if flag==0:
    w.append(i)
  
ans=[]
for i in range(H):
  if i not in h:
    r=[]
    for j in range(W):
      if j not in w:
        r.append(a[i][j])
    ans.append(r)

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

Submission status: Accepted

Solution code:
def resolve():
    H, W = map(int, input().split())
    A = []
    count = 0
    ans = []
    for _ in range(H):
        a = input()
        flag = 0
        for __ in range(W):
            if a[__] == "#":
                flag = 1
        if flag == 1:
            A.append(a)
            count += 1
    for i in range(W):
        flag = 0
        for j in range(count):
            if A[j][i] == "#":
                flag = 1
        if flag == 0:
            ans.append(i)
    for p in range(count):
        anan = ""
        for q in range(W):
            if q not in ans:
                anan += A[p][q]
        print(anan)
resolve()

Submission status: Accepted

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

B = [i for i in A if '#' in i]

C = [i for i in zip(*B) if '#' in i]

for i in zip(*C):
    print(''.join(i))

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
maze = []
for i in range(h):
    maze.append(input())
h_li = []
for i in range(h):
    exclude = True
    for j in range(w):
        if maze[i][j] == '#':
            exclude = False
    if not exclude:
        h_li.append(i)

w_li = []
for i in range(w):
    exclude = True
    for j in range(h):
        if maze[j][i] == '#':
            exclude = False
    if not exclude:
        w_li.append(i)

for i in h_li:
    ans = ''
    for j in w_li:
        ans += maze[i][j]
    print(ans)

Submission status: Accepted

Solution code:
H, W = list(map(lambda x: int(x), input().split(" ")))
A = []
ans = []
whiterows = []
whitecols = []

for i in range(H):
  A.append(list(input()))
  if A[i].count("#") == 0:
    whiterows.append(i)

tA = [list(a) for a in zip(*A)]
for j in range(W):
  if tA[j].count("#") == 0:
    whitecols.append(j)

rows = list(filter(lambda r: r not in whiterows, list(range(H))))
cols = list(filter(lambda c: c not in whitecols, list(range(W))))

for k in rows:
  ans.append("".join([A[k][l] for l in cols]))

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

Submission status: Accepted

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


for i in range(h):
    tmp = input()
    flag = 0
    for j in range(len(tmp)):
        if tmp[j] == '#':
            flag = 1
            break
    if flag == 0:
        continue
    else:
        c.append(tmp)

tate = []

for i in range(len(c[0])):
    flag = 0
    for j in range(len(c)):
        if c[j][i] == '#':
            flag = 1
            break
    if flag == 0:
        tate.append(i)

for i in range(len(c)):
    c[i] = list(c[i])
    for j in range(len(tate)):
        c[i].pop(tate[j]-j)
    c[i] = ''.join(c[i])
    print(c[i])

Submission status: Accepted

Solution code:
import numpy as np

h,w = map(int,input().split())
x = [[0 if s=="." else 1 for s in list(input())] for _ in range(h)]

for i in reversed(range(h)):
    if sum(x[i])==0:
        x.pop(i)
x = np.array(x).T.tolist()
for i in reversed(range(len(x))):
    if sum(x[i])==0:
        x.pop(i)
x = np.array(x).T.tolist()
h = range(len(x))
x = [["#" if j==1 else "." for j in x[i]] for i in h]
for i in h:
    print ("".join(x[i]))

Submission status: Accepted

Solution code:
h,w=(int(i) for i in input().strip().split(" "))
ar=[]
s=[]
for j in range(h):
    k=[i for i in input().strip()]
    if k==["."]*w:
        pass
    else:
        ar.append(k)

fin=[]
for j in range(w):
    t=[]
    for i in range(len(ar)):
        t.append(ar[i][j])
    if t==["."]*len(t):
        pass
    else:
        fin.append(t)


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

Submission status: Accepted

Solution code:
import sys
H,W=map(int,input().split())
a=list(sys.stdin)
rs,cs=[1]*H,[1]*W
for i in range(H):
    for j in range(W):
        if a[i][j]=='#':
            rs[i]=cs[j]=0
ans=''
for i in range(H):
    if rs[i]:
        continue
    r=''
    for j in range(W):
        if cs[j]:
            continue
        r+=a[i][j]
    ans+=r+'\n'
print(ans)

Submission status: Accepted

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

q,w=[1]*H,[1]*W
for i in range(H):
    for j in range(W):
        if a[i][j]=='#':
            q[i]=w[j]=0

ans=''
for i in range(H):
    if q[i]:
        continue
    row=''
    for j in range(W):
        if w[j]:
            continue
        row+=a[i][j]
    ans+=row+'\n'
    

print(ans)

Submission status: Accepted

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

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

for i in range(len(A)):
    if ''.join(A[i]) != '.'*len(A[i]):
        B.append(A[i])


C = list(zip(*B))
R = []
for i in range(len(C)):
    if ''.join(C[i]) != '.'*len(C[i]):
        R.append(C[i])

R = list(zip(*R))

for r in R:
    print(''.join(r))

Submission status: Accepted

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

    c_h = []
    c_w = []

    for i in range(h):
        flag = False
        for j in range(w):
            if a[i][j] == '#':
                flag = True
                break
        
        if flag:
            c_h.append(i)

    for i in range(w):
        flag = False
        for j in range(h):
            if a[j][i] == '#':
                flag = True
                break
        if flag:
            c_w.append(i)

    new_a = []

    if len(c_h) == 0:
        if not len(c_w) == 0:

            for i in range(h):
                temp = []
                for j in c_w:
                    temp.append(a[i][j])
                new_a.append(temp)

    elif len(c_w) == 0:
        if not lne(c_h) == 0:

            for i in range(w):
                temp = []
                for j in c_h:
                    temp.append(a[j][i])
                new_a.append(temp)

    elif not(len(c_h) == 0 or len(c_w) == 0):
        for i in c_h:
                temp = []
                for j in c_w:
                    temp.append(a[i][j])
                new_a.append(temp)
    
    else:
        pritn()
        return 0


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

if __name__ == '__main__':
    main()