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())
map =[]
for _ in range(H):
     a = list(input())
     map.append([int(x !='.') for x in a ])
memo = []
for i in range(H):
    if sum(map[i]) == 0:
        memo.append(i)
while memo:
    del map[memo[-1]]
    del memo[-1]
    H -= 1
for j in range(W):
    color = [map[x][j] for x in range(H)]
    if sum(color) == 0:
        memo.append(j)
while memo:
    for k in range(H):
        del map[k][memo[-1]]
    del memo[-1]
    W = -1
for j in map:
    a = ["." if ab == 0 else "#" for ab in j]
    print("".join(a))

Submission status: Accepted

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

yoko = []
for i in range(h):
    seta = set(a[i])
    if '#' in seta:
        yoko.append(a[i])

h = len(yoko)
w = len(yoko[0])
for i in range(w):
    tate = []
    for j in range(h):
        tate.append(yoko[j][i])
    settate = set(tate)
    if '#'not in settate:
        for j in range(h):
            yoko[j][i] = ''

ans = ''
for i in range(h):
    c = ''.join(yoko[i])
    ans += c
    if i != h-1:
        ans += '\n'
print(ans)

Submission status: Accepted

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

ly = []
lt = []
for i in range(H):
  if "#" in m[i]:
    ly.append(i)
for j in range(W):
  c = 0
  for k in range(H):
    if m[k][j] == "#":
      c += 1
      break
  if c == 1:
    lt.append(j)    
###
for i in ly:
  s =""
  for j in lt:
    s += m[i][j]
  print(s)

Submission status: Accepted

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

# 横除外
b = [i for i in a if not i.count('.') == w]
# 縦除外
h2 = len(b)
w2 = len(b[0])
ret = []
for i in range(w2):
    for x in range(h2):
        if b[x][i] == '#':
            ax = [b[xx][i] for xx in range(h2)]
            ret += [ax]
            break
    else:
        continue

for i in range(len(ret[0])):
    print(''.join([ret[x][i] for x in range(len(ret))]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
S = [tuple(input()[:-1]) for _ in [0]*H]

ex = []
ey = []

for x in range(W):
    for s in S:
        if s[x] == '#':
            break
    else:
        ex.append(x)

for y in range(H):
    if '#' in S[y]:
        continue
    ey.append(y)

for y, s in enumerate(S):
    if y in ey:
        continue
    for x, t in enumerate(s):
        if x in ex:
            continue
        print(t, end="")
    print()

Submission status: Accepted

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

R = set()
C = set(list(range(W)))
for i in range(H):
    if not "#" in A[i]:
        R.add(i)
        continue
    tmp = set()
    for j in range(W):
        if A[i][j] == ".":
            tmp.add(j)
    C &= tmp

ans = []
for i in range(H):
    if i in R:
        continue
    tmp = []
    for j in range(W):
        if j in C:
            continue
        tmp.append(A[i][j])
    ans.append(tmp)

for a in ans:
    print(*a,sep="")

Submission status: Accepted

Solution code:
def main():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    pass_row = []
    pass_col = []
    for i in range(h):
        if "#" not in a[i]:
            pass_row.append(i)
    left_row = h - len(pass_row)
    for j in range(w):
        tmp = 0
        for i in range(h):
            if i not in pass_row and a[i][j] == ".":
                tmp += 1
        if tmp == left_row:
            pass_col.append(j)
    for i in range(h):
        if i not in pass_row:
            for j in range(w):
                if j not in pass_col:
                    print(a[i][j], end="")
            print()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
G=[list(input()) for i in range(H)]
hcnt,wcnt=set(),set()
for i in range(H):
    ok=True
    for j in range(W):
        if(G[i][j]=='#'):
            ok=False
            break
    if(ok):
        hcnt.add(i)
for j in range(W):
    ok=True
    for i in range(H):
        if(G[i][j]=='#'):
            ok=False
            break
    if(ok):
        wcnt.add(j)

for i in range(H):
    cnt=0
    if(i in hcnt):
        continue
    for j in range(W):
        if(j in wcnt):
            continue
        print(G[i][j],end='')
        cnt+=1
    if(cnt>0):
        print()

Submission status: Accepted

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

b = [list(x) for x in zip(*a)]

n = []
for i in range(W):
  if b[i] == ["."] * H: 
    n.append(i)

for A in a:
  if A == ["."] * W: continue
  if len(n) == 0: 
    print("".join(A))
    continue
  ans = ""
  for i in range(W):
    if i in n: continue
    ans += A[i]
  print("".join(ans))

Submission status: Accepted

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

for _ in range(h):
    row = input()
    if '#' in row:
        mas.append(list(row))

ignore_col = []
for i in range(w):
    cnt = 0
    for j in range(len(mas)):
        if mas[j][i] == '#':
            break
        cnt += 1
    if cnt == len(mas):
        ignore_col.append(i)

for i in range(len(mas)):
    tmp = []
    for j in range(w):
        if j in ignore_col:
            continue
        tmp.append(mas[i][j])
    print(''.join(tmp))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g=[list(input()) for _ in range(h)]
gg=[]
for l in zip(*g):
	if not all(x=="." for x in l):
		gg.append(l)
ggg=[]
for l in zip(*gg):
	if not all(x=="." for x in l):
		print("".join(l))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[j for j in input()] for i in range(h)]
b=[x for x in a if "#" in x]
c=zip(*[y for y in zip(*b) if "#" in y])
for d in c:print("".join(d))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
row = []
col = []
for i in range(H):
    if a[i] != '.' * W:
        row.append(i)
for j in range(W):
    if any(a[i][j] == '#' for i in range(H)):
        col.append(j)
ans = [''.join(a[r][c] for c in col) for r in row]
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    t = list(input())
    a.append(t)
id = []
jd = []
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            if i not in id:
                id.append(i)
            if j not in jd:
                jd.append(j)
jd.sort()
for i in id:
    for j in jd:
        print(a[i][j], end="")
    print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
grid = []
curh = h
curw = w
for i in range(h):
    grid.append(list(input()))
i = 0
while i < curh:
    if grid[i] == ["."]*curw:
        for j in range(i,curh-1):
            grid[j] = grid[j+1]
        grid.pop(curh-1)
        curh -= 1
        i -= 1
    i += 1
i = 0
while i < curw:
    for j in range(curh):
        if grid[j][i] == "#":
            break
    else:
        for j in range(curh):
            for k in range(i,curw-1):
                grid[j][k] = grid[j][k+1]
            grid[j].pop(curw-1)
        curw -= 1
        i -= 1
    i += 1
for i in range(curh):
    print("".join(grid[i]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
c=[]
ng_h,ng_w=[],[]
for i in range(h):
  ok=True
  for j in range(w):
    if a[i][j]!=".":
      ok=False
      break
  if ok:
    ng_h.append(i)

for i in range(w):
  ok=True
  for j in range(h):
    if a[j][i]!=".":
      ok=False
      break
  if ok:
    ng_w.append(i)

for i in range(h):
  t=""
  for j in range(w):
    if i in ng_h:continue
    if j in ng_w:continue
    t+=a[i][j]
  if t!="":
    c.append(t)
print(*c,sep='\n')

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
ans = []
for i in range(h):
    a = list(input())
    if a[0]=="." and len(set(a)) == 1:
        continue
    ans.append(a)

ans1 = []
for j in list(zip(*ans)):
    if j[0]=="." and len(set(j)) == 1:
        continue
    ans1.append(j)

for k in list(zip(*ans1)):
    print( ''.join(k))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
mapping = []
judge = "".join(["."]*w)
t = 0
for i in range(h):
  key = input()
  if key != judge:
    mapping.append([])
    for j in range(w):
      mapping[-1].append(key[j])
  else:
    t += 1

for i in range(w-1, -1, -1):
  for j in range(h-t):
    if mapping[j][i] == "#":
      break
    if j == h-t-1:
      for l in range(h-t):
        mapping[l].pop(i)

for i in range(h-t):
  print("".join(mapping[i]))

Submission status: Accepted

Solution code:
import itertools

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

area = []
for i in range(h):
    array = list(input())
    area.append(array)

a = list(itertools.chain.from_iterable(area))

yoko = []
tate = []

for i in range(h):
    cnt = 0
    for j in range(w):
        if area[i][j] == '#':
            cnt += 1
    if cnt == 0:
        yoko.append(i)

for i in range(w):
    b = a[i::w]
    if len(set(b)) == 1 and '.' in set(b):
        tate.append(i)

for i in range(h):
    flg = False
    for j in range(w):
        if j in set(tate):
            continue
        elif i in set(yoko):
            flg = True
            continue
        else:
            print(area[i][j], end='')
    if flg == False:
        print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]
y= 0
while y < h:
    x = 0
    flag = True
    while x < w:
        if a[y][x]=="#":
            flag = False
        x += 1
    if flag == True:
        a.pop(y)
        h -= 1
        y = 0
    else:
    	y += 1
x = 0
while x < w:
    y = 0
    flag = True
    while y < h:
        if a[y][x]=="#":
            flag = False
        y += 1
    if flag == True:
        for i in range(h):
            a[i].pop(x)
        w -= 1
        x = 0
    else:
    	x += 1

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    h, w = map(int, input().split())
    l = []
    for _ in range(h):
        a = list(input())
        if not '#' in a:
            continue
        l.append(a)
    l = np.array(l)
    m = np.rot90(l)
    n = []
    for a in m:
        if not '#' in a:
            continue
        n.append(a)
    ans = np.array(n)
    ans = np.rot90(ans, -1)
    for i in ans:
        print(*i, sep='')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin,setrecursionlimit
setrecursionlimit(10 ** 7)
h,w = map(int,stdin.readline().rstrip().split())
li = [["" for i in range(w)]for j in range(h)]
for i in range(h):
    s = stdin.readline().rstrip()
    for j in range(w):
        li[i][j] = s[j]
lin = []
for i in li:
    if i != ["."]*w:
        lin.append(i)
out = []
for i in range(w):
    flag = True
    for j in range(len(lin)):
        if lin[j][i] == "#":
            flag = False
    if flag:
        out.append(i)

lis = []
for i in lin:
    case = []
    for j,k in enumerate(i):
        if j in out:
            continue
        case.append(k)
    lis.append(case)

for i in lis:
    print("".join(i))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
h_b = []
w_b = []
for i in range(h):
    if "#" in grid[i]:
        h_b.append(i)
grid_t = [list(x) for x in zip(*grid)]
for i in range(w):
    if "#" in grid_t[i]:
        w_b.append(i)
ans = []
for i in h_b:
    crt = []
    for j in w_b:
        crt.append(grid[i][j])
    ans.append(crt)
for i in range(len(ans)):
    print("".join(ans[i]))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
a = [readline().rstrip().decode() for i in range(h)]
memo_w = [False] * h
memo_h = [False] * w
for i in range(h):
    flag = True
    for j in range(w):
        if a[i][j] == '#':
            flag = False
            break
    if flag:
        memo_w[i] = True
for i in range(w):
    flag = True
    for j in range(h):
        if a[j][i] == '#':
            flag = False
            break
    if flag:
        memo_h[i] = True
for i in range(h):
    if not memo_w[i]:
        ans = ''
        for j in range(w):
            if not memo_h[j]:
                ans += a[i][j]
        print(ans)

Submission status: Accepted

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

skip_col = [False] * W
for i in range(len(board[0])):
    for j in range(H):
        if board[j][i] == '#':
            break
    else:
        skip_col[i] = True

for i in range(H):
    if all([c == '.' for c in board[i]]):
        continue
    for j in range(W):
        if skip_col[j]:
            continue
        print(board[i][j], end='')
    print('')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
s = [list(input()) for i in range(n)]
ss = []
for i in range(n):
    if s[i].count('.') == m:
        continue
    ss.append(s[i])
sss = [[]for _ in range(len(ss))]
for i in range(m):
    ok = False
    ln = len(ss)
    for j in range(ln):
        if ss[j][i] == '#':
            ok = True
    if ok:
        for j in range(ln):
            sss[j].append(ss[j][i])

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

Submission status: Accepted

Solution code:
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    cut_h = []
    cut_w = []
    for h in range(H):
        if all(s == "." for s in A[h]):
            cut_h.append(h)
    for w in range(W):
        if all("." == A[i][w] for i in range(H)):
            cut_w.append(w)
    for h in range(H):
        if h in cut_h:
            continue
        for w in range(W):
            if w in cut_w:
                continue
            print(A[h][w], end="")
        print()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

skip_col = [False] * W
for i in range(len(board[0])):
    for j in range(H):
        if board[j][i] == '#':
            break
    else:
        skip_col[i] = True

for i in range(H):
    if all([c == '.' for c in board[i]]):
        continue
    for j in range(W):
        if skip_col[j]:
            continue
        print(board[i][j], end='')
    print('')

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    cell = [list(input()) for _ in range(H)]
    rlist = list()
    clist = list()
    for i in range(H):
        if cell[i].count(".") == W:
            rlist.append(i)
    for j in range(W):
        c = 0
        for i in range(H):
            if cell[i][j] == ".":
                c += 1
            if c == H:
                clist.append(j)
    for i in range(H):
        if i in rlist:
            pass
        else:
            for j in range(W):
                if j in clist:
                    pass
                else:
                    print(cell[i][j], end="")
            print()
main()

Submission status: Accepted

Solution code:
# solution
import io

n, m = map(int, input().split())
array = []

for i in range(n-1, -1, -1):
    qwe = list(input())
    if qwe!=["."]*m:
        array.append(qwe)

for j in range(m-1, -1, -1):
    cnt = 0
    for k in range(len(array)):
        if array[k][j]==".":
            cnt += 1
    if cnt ==len(array):
        for k in range(len(array)):
            array[k].pop(j)

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

Submission status: Accepted

Solution code:
import numpy as np


def yoko(row):
    cnt = sum(row)
    return cnt == len(row)


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

    for i in range(h):
        b = input()
        a += [1 if c == '.' else 0 for c in b]
    a = np.array(a).reshape(h, w)

    while True:
        cnt = 0
        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        if cnt >= 2:
            break

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


main()

Submission status: Accepted

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

for i in range(h):
    s = a[i*w:-~i*w]
    if s != '.' * w:
        b += s

nh = len(b) // w
for j in range(w):
    s = b[j::w]
    if s != '.' * nh:
        c += s

nw = len(c) // nh
for i in range(nh):
    print(c[i::nh])

Submission status: Accepted

Solution code:
# ABC 107: B – Grid Compression
h, w = [int(s) for s in input().split()]
a = [input() for _ in range(h)]

rows = []
columns = []

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

for i in range(h):
    if a[i].count('#') == 0:
        rows.append(i)

for i in range(h):
    tmp = ''
    if i not in rows:
        for j in range(w):
            if j not in columns:
                tmp += a[i][j]
        print(tmp)

Submission status: Accepted

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

grid = [a for a in grid if '#' in a]

grid = list(zip(*[a for a in zip(*grid) if '#' in a]))
for a in grid:
    print(''.join(a))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
A = []
for _ in range(H):
    A.append(list(input()))
col = []
row = []
for i in range(H):
    if not '#' in A[i]:
        row.append(i)
for i in range(W):
    flag = 1
    for j in range(H):
        if '#' == A[j][i]:
            flag = 0
    if flag:
        col.append(i)
for i in range(H):
    if i in row:
        continue
    for j in range(W):
        if j in col:
            continue
        print(A[i][j], end='')
    print()

Submission status: Accepted

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

A=[0]*H
i=0
while i<H:
    A[i]=list(input())
    i+=1

B=[]
for i in A:
    if '#'in i:
        B.append(i)

j=W-1
while j>=0:
    if all(i[j]=='.' for i in B):
        k=0
        while k<len(B):
            B[k].pop(j)
            k+=1
    j-=1




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

Submission status: Accepted

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

MAP=  [[0 for i in range(W)] for i in range(H)]

HLIST=[0 for i in range(H)]
WLIST=[0 for i in range(W)]

for h in range(H):
    L=list(input())
    MAP[h]=L
    for w in range(W):
        if(MAP[h][w]=="#"):
            HLIST[h]+=1
            WLIST[w]+=1
for h in range(H):
    if(HLIST[h]!=0):
        for w in range(W):
            if(WLIST[w]!=0):
                if(MAP[h][w]=="#"):
                    print("#",end="")
                else:
                    print(".",end="")
        print("")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for _ in range(h):
    ai = input()
    if '#' in ai:
        a.append(ai)
ans=['']*len(a)
for i in range(w):
    if sum([a[j][i]=='#' for j in range(len(a))])==0:
        continue
    for j in range(len(a)):
        ans[j]+=a[j][i]
for ansi in ans:
    print(ansi)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    b = input()
    a.append(b)
b = []
flag = 0
for i in range(H):
    flag = 0
    for j in range(W):
        if a[i][j] == '#':
            flag = 1
    if flag == 1:
        d = [1 for i in range(W)]
        b.append(d)
    else:
        d = [0 for i in range(W)]
        b.append(d)
for i in range(W):
    flag = 0
    for j in range(H):
        if a[j][i] == '#':
            flag = 1
    if flag == 0:
        for j in range(H):
            b[j][i] = 0

for i in range(H):
    flag = 0
    for j in range(W):
        if b[i][j] == 1:
            print(a[i][j], end = "")
            flag = 1
        if flag == 1 and j == W - 1:
            print("")

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

H, W = nm()
a = [list(ns()) for _ in range(H)]

def compress(a):
    out = []
    for line in a:
        if '#' in line:
            out.append(line)
    return out

temp = compress(a)
temp2 = compress([list(i) for i in zip(*temp)])
ans = [list(i) for i in zip(*temp2)]

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

Submission status: Accepted

Solution code:
def resolve():
    h,w=map(int,input().split())
    mass = []
    length=0
    for i in range(h):
        a=list(input())
        if "#" in a:
            mass.append(a)
            length+=1
    for i in reversed(range(w)):
        total=0
        for j in range(length):
            if mass[j][i]==".":
                total+=1
        if total==length:
            for j in range(length):
                del mass[j][i]
    for i in range(length):
        print("".join(mass[i]))

resolve()

Submission status: Accepted

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

A = [[a for a in input()] for _ in range(H)]
flag = True
while flag:
    flag = False
    # 行方向
    rm = []
    for i, a in enumerate(A):
        if '#' not in a:
            rm.append(i)
    if len(rm) > 0:
        flag = True
        A = [a for i, a in enumerate(A) if i not in rm]
    # 列方向
    rm = []
    A = list(zip(*A))
    for i, a in enumerate(A):
        if '#' not in a:
            rm.append(i)
    if len(rm) > 0:
        flag = True
        A = [a for i, a in enumerate(A) if i not in rm]
    A = list(zip(*A))

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

Submission status: Accepted

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

for i in range(W)[::-1]:
    c = 0
    for j in range(len(b)):
        if b[j][i] == ".":
            c += 1
    if c == len(b):
        for j in range(len(b)):
            b[j].pop(i)

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
f = [input()for i in range(h)]
H = []
W = []
for i in range(h):
    ok = True
    for j  in range(w):
        if f[i][j] == '#':
            ok = False
            break
    if ok:H.append(i)
for i in range(w):
    ok = True
    for j in range(h):
        if f[j][i] == '#':
            ok = False
            break
    if ok:W.append(i)
nf = []
for i in range(h):
    p = []
    for j in range(w):
        if  i in H or j in W:continue
        p.append(f[i][j])
        
    if len(p) > 0:nf.append(p)
for i in range(len(nf)):
    print("".join(nf[i]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[0 for j in range(w)] for i in range(h)]
for i in range(h):
  s=input()
  for j in range(w):
    if s[j]==".":
      a[i][j]=0
    else:
      a[i][j]=1
H=[]
for i in range(h):
  if sum(a[i])==0:
    H.append(i)
a2=[[0 for j in range(w)] for i in range(h-len(H))]
key=0
for _ in range(h):
  if _ in H:
    continue
  else:
    for j in range(w):
      a2[key][j]=a[_][j]
    key+=1
Q=[]
S=[0]*w
for j in range(w):
  for i in range(h-len(H)):
    S[j]+=a2[i][j]
for j in range(w):
  if S[j]==0:
    Q.append(j)
key=0


a3=[[0 for j in range(w-len(Q))] for i in range(h-len(H))]
for j in range(w):
  if j in Q:
    continue
  elif j not in Q:
    for i in range(h-len(H)):
      a3[i][key]=a2[i][j]
    key+=1

for i in range(h-len(H)):
  for j in range(w-len(Q)):
    a3[i][j]=str(a3[i][j])
    if a3[i][j]=="0":
      a3[i][j]="."
    elif a3[i][j]=="1":
      a3[i][j]="#"
ans=[""]*(h-len(H))
for i in range(h-len(H)):
  for j in range(w-len(Q)):
    ans[i]+=a3[i][j]
  print(ans[i])

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a=[]
for i in range(h):
    b = input()
    f = False
    for j in range(len(b)):
        if b[j] == '#':
            f = True
    if f:
        a.append(list(b))

f = True
cnt = 0
for i in range(len(a[0])):
    for j in range(len(a)):
        if(a[j][i-cnt] == '#'):
            f = False
    if f:
        for j in range(len(a)):
            del a[j][i-cnt]
        cnt += 1
    f = True

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

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
a = []
for i in range(h): #入力の時点で横を取り除く
    x = list(input())
    if x.count(".") == w:
        continue
    else:
        a.append(x)

n = len(a)
a = [list(x) for x in zip(*a)] #転置
x = 0 #popの調整

for i in range(w):
    if a[i-x].count(".") == n:
        a.pop(i-x)
        x += 1

a = [list(x) for x in zip(*a)] #転置して戻す

for i in range(len(a)): #出力
    for s in a[i]:
        print(s, end ="")
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
T = [input() for _ in range(h)]
flagRow = [0] * h
flagColumn = [0] * w

for i in range(h):
    for j in range(w):
        if T[i][j] == "#":
            flagRow[i] = 1
            flagColumn[j] = 1

for i in range(h):
    if flagRow[i] == 1:
        for j in range(w):
            if flagColumn[j] == 1:
                print(T[i][j], end = "")
        print("")

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]
y =0;x=0
while y < h:
    flag = True
    for x in range(w):
        if a[y][x]=='#':
            flag = False
    
    if flag == True:
        a.pop(y)
        h -= 1
        y = 0
    else:
    	y += 1
x = 0 
while x < w:
    flag = True
    for y in range(h):
        if a[y][x]=='#':
            flag = False
    
    if flag == True:
        for s in range(h):
            a[s].pop(x)
        w -= 1
        x = 0
    else:
        x += 1
            
for i in range(h):
    print(''.join(a[i]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = []
for i in range(H):
    x = list(input())
    if '#' in x:
        a.append(x)
def trans(a):
    x = [i for i in zip(*a)]
    return x
at = trans(a)
an = []
for i in at:
    if '#' in i:
        an.append(i)
ans = trans(an)
for i in ans:
    print(*i,sep = '')

Submission status: Accepted

Solution code:
h, w, *d = open(0).read().split()
h, w = int(h), int(w)
d = [i for i in d if "#" in i]
d = zip(*[j for j in zip(*d) if "#" in j])
print(*["".join(p) for p in d], sep="\n")

Submission status: Accepted

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

for i in range(H):
    a.append(input())

row = [i for i in range(H)]
column = [i for i in range(W)]

row_delete = []
column_delete = []

for i in range(H):
    flag_delete = True
    for j in range(W):
        if a[i][j] == "#":
            flag_delete = False
            break
    if flag_delete == True:
        row_delete.append(i)

for i in range(W):
    flag_delete = True
    for j in range(H):
        if a[j][i] == "#":
            flag_delete = False
            break
    if flag_delete == True:
        column_delete.append(i)

# 行
for i in row_delete:
    row.remove(i)
# 列
for i in column_delete:
    column.remove(i)

ans = [["" for _ in range(len(column))] for _ in range(len(row))]

count_row = 0
for i in row:
    count_column = 0
    for j in column:
        ans[count_row][count_column] = a[i][j]
        count_column += 1
    count_row += 1

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

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 = [input() for _ in range(h)]

remove_a = []
for i in range(h):
    if '#' in a[i]:
        remove_a.append(list(a[i]))

n = len(remove_a)
l = []
for i in range(w):
    s = ''
    for j in range(n):
        s += remove_a[j][i]
    if '#' in s:
        l.append(list(s))

ans = ''
for i in range(len(l[0])):
    s = ''
    for j in range(len(l)):
        s += l[j][i]
    ans += s
    if i != len(l[0])-1:
        ans += '\n'
print(ans)