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())
L=[list(input()) for _ in range(H)]
L=[l for l in L if "#" in l]
#リストの中のリストで#を含まないリストは取り除く
LL=list(zip(*L))
#同じサブインデックスをもつ要素からなる配列を作る
LL=[l for l in LL if "#" in l]
L=list(zip(*LL))
for l in L:
  print("".join(l))

Submission status: Accepted

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

rmh = 0
for h in range(H):
    h -= rmh
    ok = True
    for w in range(W):
        if state[h][w] == '#':
            ok = False
            break
    if ok:
        state.pop(h)
        rmh += 1
H -= rmh
rmw = 0
for w in range(W):
    w -= rmw
    ok = True
    for h in range(H):
        if state[h][w] == '#':
            ok = False
            break
    if ok:
        for h in range(H):
            state[h].pop(w)
        rmw += 1

for s in state:
    print(''.join(s))

Submission status: Accepted

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

aLst = [list(map(str, input().split())) for i in range(H)]

deIndex = []
for i in range(H):
    if aLst[i][0].count('.') == W:
        deIndex.append(i)
deIndex.sort(reverse=True)

for i in deIndex:
    del aLst[i]
H -= len(deIndex)
deIndex.clear()

for i in range(W):
    kCnt = 0
    for j in range(H):
        if aLst[j][0][i] == '.':
            kCnt += 1

    if kCnt == H:
        deIndex.append(i)
if len(deIndex) == 0:

    for i in range(H):
        print(''.join(aLst[i]))
else:
    deIndex.sort(reverse=True)
    tmplist = [['' for i in range(W)] for j in range(H)]
    for j in range(H):
        tmplist[j] = list(aLst[j][0])

    for i in range(H):
        for j in deIndex:
            del tmplist[i][j]

    W -= len(deIndex)
    for i in range(H):
        print(''.join(tmplist[i]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, i = LI()
    print(n-i+1)
    return

#B
def B():
    h, w = LI()
    a = SR(h)
    dy = defaultdict(int)
    dx = defaultdict(int)
    for y in range(h):
        for x in range(w):
            if a[y][x] == "#":
                dx[x] = 1
                dy[y] = 1
    dy = list(sorted(dy.items(), key=lambda x: x[0]))
    dx = list(sorted(dx.items(), key=lambda x: x[0]))
    for y,_ in dy:
        for x,_ in dx:
            print(a[y][x], end="")
        print()


    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

p = ['.']*W
while p in L:
    L.remove(p)
    H -= 1

L2 = [[0]*H for _ in range(W)]
for h in range(H):
    for w in range(W):
        L2[w][h] = L[h][w]


q = ['.']*H
while q in L2:
    L2.remove(q)
    W -= 1

ans = [[0]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        print(L2[w][h], end="")
    print()

Submission status: Accepted

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

L = []
R = []

for i in range(H):
  R_cnt = 0
  for j in range(W):
    if A[i][j] == '.':
      R_cnt += 1
  if R_cnt == W:
    R.append(i)

for j in range(W):
  L_cnt = 0
  for i in range(H):
    if A[i][j] == '.':
      L_cnt += 1
  if L_cnt == H:
    L.append(j)

for i in range(H):
  S = []
  for j in range(W):
    if i in R:
      break
    elif j in L:
      continue
    else:
      S.append(A[i][j])
  if len(S) > 0:
    print(''.join(S))

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
List = []
for i in range(H):
    List.append([a for a in input()])
i = 0
j = 0
while i < len(List):
    if List[i].count("#") == 0:
        del List[i]
        i -= 1
    i += 1

while j < len(List[0]):
    c = 0
    for k in range(len(List)):
        if List[k][j] == ".":
            c += 1
    if c == len(List):
        for k in range(len(List)):
            List[k] = List[k][:j] + List[k][j+1:]
        j -= 1
    j += 1

for l in range(len(List)):
    print("".join(List[l]))

Submission status: Accepted

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

cnt = 0
while True:
  flag = True
  for i in range(H):
    tmp = 0
    vis = 0
    for j in range(W):
      if vissible[i][j]:
        vis += 1
      if vissible[i][j] and grid[i][j] == '.':
        tmp += 1
    if vis and tmp == vis:
      for j in range(W):
        vissible[i][j] = False
      flag = False
  for j in range(W):
    tmp = 0
    vis = 0
    for i in range(H):
      if vissible[i][j]:
        vis += 1
      if vissible[i][j] and grid[i][j] == '.':
        tmp += 1
    if vis and tmp == vis:
      for i in range(H):
        vissible[i][j] = False
      flag = False
  if flag:
    break
  if cnt > 10:
    break
  cnt += 1
for i in range(H):
  flag = False
  for j in range(W):
    if vissible[i][j]:
      print(grid[i][j], end='')
      flag = True
  if flag:
    print()

Submission status: Accepted

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

for _ in range(H):
    a = list(input())
    if a.count('.') == W:
        a = len(a) * ['!']
    lines.append(a)

for w in range(W):
    c = True
    for h in range(H):
        if lines[h][w] == '#':
            c = False
            break
    if c:
        for h in range(H):
            lines[h][w] = '!'

for l in lines:
    if l.count('!') == W:
        continue
    for c in l:
        print('' if c == '!' else c, end='')
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
field = []
for i in range(0, H):
	S = input()
	lst = []
	for j in range(0, W):
		lst.append(S[j])
	if '#' in lst:
		field.append(lst)
for i in range(0, W):
	flag = True
	for j in range(0, len(field)):
		if field[j][i] == '#':
			flag = False
			break
	if flag:
		for j in range(0, len(field)):
			field[j][i] = ''
for i in range(0, len(field)):
	ans = ''
	for j in range(0, W):
		ans = ans + field[i][j]
	print(ans)

Submission status: Accepted

Solution code:
r,c=map(int,input().split())
mat=[list(input()) for i in range(r)]

r_chk=[0]*r
c_chk=[0]*c

for i in range(r):
	for j in range(c):
		if mat[i][j]=='#':
			r_chk[i]=1
			c_chk[j]=1

for i in range(r):
	chk=0
	for j in range(c):
		if r_chk[i]==1 and c_chk[j]==1:     
			print(mat[i][j],end='')
			chk=1
	if chk==1:
		print('')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
li = []
for i in range(h):
    a = list(input())
    li.append(a)
li2 = li.copy()
c = 0
for i in range(h):
    for j in range(w):
        c = 0
        if li[i][j] == ".":
            continue
        elif li[i][j] == "#":
            c = 1
            break
    if c == 0:
        li[i] = ["a"] * w
d = 0
n = []
for i in range(w):
    for j in range(h):
        d = 0
        if li[j][i] == "." or li[j][i] == "a":
            continue
        else:
            d = 1
            break
    if d == 0:
        n.append(i)
for i in n:
    for j in range(h):
        li[j][i] = "a"

for i in range(h):
    grid = ""
    for x in li[i]:
        if x != "a":
            grid += x
    if grid != "":
        print(grid)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
e = []
f = [True] * b
for i in range(a):
    c = list(input())
    d = True
    for j in range(b):
        if c[j] == "#" and d:
            d = not d
        if c[j] == "#" and f[j]:
            f[j] = not f[j]
    if not d:
        e.append(c)
for i in range(len(e)):
    g = ""
    for j in range(b):
        if not f[j]:
            g += e[i][j]
    print(g)

Submission status: Accepted

Solution code:
import numpy as np

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

board = np.array([list(input()) for i in range(h)])

t_h = []
t_w = []
for i in range(h):
    if np.count_nonzero(board[i] == ".") != w:
        t_h.append(i)
for i in range(w):
    if np.count_nonzero(board[:,i] == ".") != h:
        t_w.append(i)

for y in t_h:
    for x in t_w:
        print(board[y][x],end="")
    print()

Submission status: Accepted

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

WHITE='.'
print_row=[]
print_col=[]
for i in range(H):
    for j in range(W):
        if a[i][j] != WHITE:
            if i not in print_row:
                print_row.append(i)
            if j not in print_col:
                print_col.append(j)

for i in range(H):
    linefeed = False
    for j in range(W):
        if i in print_row and j in print_col:
            linefeed = True
            print(a[i][j], sep="", end="")
    if linefeed:
        print(sep="")

Submission status: Accepted

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

rr = []
for i in range(h):
    c = Counter(a[i]).most_common()
    if len(c) > 1 or c[0][0] == '#':
        rr.append(i)

rc = []
for i in range(w):
    c = Counter([x[i] for x in a]).most_common()
    if len(c) > 1 or c[0][0] == '#':
        rc.append(i)

a = '\n'.join(''.join(a[j][i] for i in rc) for j in rr)
print(a)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
cc=[input() for i in range(a)]
c=[[""for i in range(b)]for j in range(a)]
for i in range(a):
  for j in range(b):
    c[i][j]=cc[i][j]
d=[]
e=0
for i in range(a):
  e=0
  for j in range(b):
    if c[i][j]=="#":
      e=1
  if e==0:
    d.append(i)
for i in d:
  c.pop(i)
  for j in range(len(d)):
    d[j]=d[j]-1
d=[]
for i in range(b):
  e=0
  for j in range(len(c)):
    if c[j][i]=="#":
      e=1
  if e==0:
    d.append(i)
for i in d:
  for j in range(len(c)):
    c[j].pop(i)
  for j in range(len(d)):
    d[j]=d[j]-1

for i in range(len(c)):
  g=""
  for j in range(len(c[i])):
    g+=c[i][j]
  print(g)

Submission status: Accepted

Solution code:
import sys
import numpy as np
h,w = map(int,input().split())
a = [input() for i in range(h)]
a = [list(map(int,list(a[i].replace("#","1").replace(".","0")))) for i in range(h)]

aa = np.array(a)

tate = np.sum(aa,axis=0)
yoko = np.sum(aa,axis=1)

for i in range(len(tate)-1,-1,-1):
  if tate[i] == 0:
    aa = np.delete(aa,i,1)

for i in range(len(yoko)-1,-1,-1):
  if yoko[i] == 0:
    aa = np.delete(aa,i,0)

aa = np.where(aa == 0, ".", aa)
aa = np.where(aa == '1', "#", aa)

a = aa.tolist()

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
g = []
ans = []
for _ in range(h):
    s = [c for c in input()]
    g.append(s)
del_col = []
for j in range(w):
    col = [r[j] for r in g]
    if all([x == '.' for x in col]) :
        del_col.append(j)
del_col.sort(reverse=True)

for i in range(h):
    if not all([x == '.' for x in g[i]]):
        for d in del_col:
            g[i].pop(d)
        ans.append(g[i])
for r in ans:
    print(''.join(r))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
A = [list(input()) for i in range(h)]
AH = []
AW = []
for i in range(h):
    if '#' in A[i]:
        AH.append(i)
for j in range(w):
    flag = 0
    for i in range(h):
        if A[i][j]=='#':
            flag = 1
    if flag:
        AW.append(j)
for i in AH:
    res = []
    for j in AW:
        res.append(A[i][j])
    print("".join(res))

Submission status: Accepted

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

for i in range(h-1, -1, -1):
    s = list(input())
    if s!=["."]*w:
        l.append(s)

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

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

Submission status: Accepted

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

ans=[]

for i in range(h):
    if "#" in l[i]:
        ans.append(l[i])
        
for i in range(w):
    if all([ans[j][i]=="." for j in range(len(ans))]):
        for k in range(len(ans)):
            ans[k]=list(ans[k])
            ans[k][i]=""

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

Submission status: Accepted

Solution code:
H,W=map(int, input().split())
s=[]
for _ in range(H):
    s.append(list(input()))
x = []
y = []
for i in range(len(s)):
    if set(s[i])=={"."}: #残すのはset(i)==2
        x.append(i)
for i in range(len(s[0])):
    y_check = []
    for j in range(len(s)):
        y_check.append(s[j][i])
    if set(y_check)=={"."}:
        y.append(i)
for i in x[::-1]:
    del s[i]
for j in range(len(s)):
    for i in y[::-1]:
        del s[j][i]
for i in s:
    for j in i:
        print(j,end="")
    print("")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
board = [input() for _ in range(h)]
ansH = [False] * h
ansW = [False] * w
for i in range(h):
    for j in range(w):
        if(board[i][j] == '#'):
            ansH[i] = True
            ansW[j] = True

for i in range(h):
    if(ansH[i] == False):
        continue
    ans = ""
    for j in range(w):
        if(ansW[j]):
            ans += board[i][j]
    print(ans)

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
B = []
for _ in range(H):
    line = input()
    for l in line:
        if l == "#":
            B.append(line)
            break;

White = []
for i in range(W):
    flag = True
    for j in range(len(B)):
        if B[j][i] == "#":
            flag = False
    if flag:
        White.append(i)

for i in range(len(B)):
    line = B[i]
    for i, l in enumerate(line):
        if i not in White:
            print(l,end="")
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    arr=list(str(input()))
    if "#" in arr:a.append(arr)
for i in range(w):
    if all ([a[j][i]=="." for j in range(len(a))]):
        for k in range(len(a)):
            a[k][i]=""
for i in a:
    print("".join(i))

Submission status: Accepted

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

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

a = [list(input()) for _ in range(h)]
ans = [['.']*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '.':
            for k in range(h):
                if a[k][j] == '.':
                    continue
                else:
                    break
            else:
                for k in range(h):
                    ans[k][j] = None
            for k in range(w):
                if a[i][k] == '.':
                    continue
                else:
                    break
            else:
                for k in range(w):
                    ans[i][k] = None
        if a[i][j] == '#':
            ans[i][j] = '#'
for i in range(h):
    ans[i] = [i for i in ans[i] if i]
for i in range(h):
    if len(ans[i]) != 0:
        print(''.join(ans[i]))

Submission status: Accepted

Solution code:
import numpy as np
import sys

buf = sys.stdin.buffer
H,W = map(int,buf.readline().split())

grid = np.frombuffer(buf.read(H*(W+1)), dtype='S1').reshape((H,W+1))
grid = grid[:,:-1]

select_col = (grid == b'#').any(axis = 0)
select_row = (grid == b'#').any(axis = 1)

grid = grid[select_row, :]
grid = grid[:, select_col]
grid = grid.astype(str)

print('\n'.join(''.join(row) for row in grid))

Submission status: Accepted

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


wlist = []
hlist = []
harray = []
for i in range(H):
    flag = 0
    for j in range(W):
        if l[i][j] == "#":
            flag = 1
    if flag == 1:
        hlist.append(i)
for i in hlist:
    harray.append(l[i])
H = len(harray)

for i in range(W):
    flag = 0
    for j in range(H):
        if harray[j][i] == "#":
            flag = 1
    if flag == 0:
        wlist.append(i)
for i in wlist:
    for j in range(H):
        harray[j][i] = "n"

for i in harray:
    for x in i:
        if x != "n":
            print(x,end="")
    print()

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = [True] * a
d = [True] * b
f = []
for i in range(a):
    e = input()
    g = []
    for j in range(b):
        g.append(e[j])
        if e[j] == "#":
            if c[i]:
                c[i] = not c[i]
            if d[j]:
                d[j] = not d[j]
    f.append(g)
for i in range(len(c)):
    if not c[i]:
        h = ""
        for j in range(len(d)):
            if not d[j]:
                h += f[i][j]
        print(h)

Submission status: Accepted

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

row = [False] * h
col = [False] * w
#print(row)
#print(col)
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
#print(row)
#print(col)
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)]
#print(a)
a = [ai for ai in a if set(ai) != {'.'}] #.がないときにはリストに入れる tf .のみを剥がす
#print(a)
a = ["".join([a[i][j] for i in range(len(a))]) for j in range(len(a[0]))] #iとjの反転
#print(a)
#for ai in a:
#    print(ai)
a = [ai for ai in a if set(ai) != {'.'}]
#print(a)
a = ["".join([a[i][j] for i in range(len(a))]) for j in range(len(a[0]))]
#print(a)
for ai in a:
    print(ai)

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
row = []
erase = []
for i in range(H):
    r = list(input())
    count = 0
    for j in range(W):
        if r[j] == '.':
            count += 1
    if count != W:
        row.append(r)        

for k in range(W): 
    count2 = 0
    for l in range(len(row)): 
        if row[l][k] == '.':
            count2 += 1
    if count2 == len(row):
        erase.append(k)

answer = []
if len(erase) > 0:
    for m in range(len(row)):
        ans = ''
        for n in range(len(row[m])):
            if n not in erase:
                ans += row[m][n]
        answer.append(ans)
    
else:
    for p in range(len(row)):
        ans = ''
        for q in range(len(row[p])):
            ans += row[p][q]
        answer.append(ans)
    

for o in answer:
    print(o)

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
a=np.reshape(a,(h,w))
a=a[:,np.any(a=='#',axis=0)][np.any(a=='#',axis=1),:]
[print("".join(a[i])) for i in range(a.shape[0])]

Submission status: Accepted

Solution code:
#n = int(input())
h, w = map(int,input().split())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split())) for i in range(n)]
ls = [input() for i in range(h)]
tmp = [i for i in ls if i.count('.') != w]
def t(tmp):
  ls = []
  for i in range(len(tmp[0])):
    ls.append("")
    for j in tmp:
      ls[i] += j[i]
  return ls
tmp = t(tmp)
ls = [i for i in tmp if i.count('.') != len(tmp[0])]
for i in t(ls):
  print(i)

Submission status: Accepted

Solution code:
import numpy as np

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

    for i in range(h):
        if a[i].count("#") == 0:
            a[i] = a[i].replace(".", "x")

    a = np.array([list(i) for i in a])
    a = a.transpose()
    a = ["".join(i) for i in a]

    for i in range(w):
        if a[i].count("#") == 0:
            a[i] = a[i].replace(".", "x")

    a = np.array([list(i) for i in a])
    a = a.transpose()
    a = ["".join(i) for i in a]

    for i in a:
        if i.replace("x", "") == "":
            continue
        print(i.replace("x", ""))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(len(a)):
    s = ''
    for j in range(W):
        if j in ls:
            continue
        else:
            s += a[i][j]
    ans.append(s)
print(*ans, sep='\n')

Submission status: Accepted

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

a = [ai for ai in a if set(ai) != {'.'}]
a = ["".join([a[i][j] for i in range(len(a))]) for j in range(len(a[0]))]
a = [ai for ai in a if set(ai) != {'.'}]
a = ["".join([a[i][j] for i in range(len(a))]) for j in range(len(a[0]))]

for ai in a:
    print(ai)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
r = [list(input()) for i in range(h)]
for i in range(h):
    if not '#' in r[i]:
        r[i] = 'Nan'
r = [i for i in r if i != 'Nan']
l = list(map(list, zip(*r)))
for i in range(len(l)):
    if not '#' in l[i]:
        l[i] = 'Nan'
l = [i for i in l if i != 'Nan']
l = list(map(list, zip(*l)))
for i in range(len(l)):
    print(''.join(l[i]))

Submission status: Accepted

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

index_h = []
index_w = []

for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            break
        if j == W - 1:
            index_h.append(i)

for j in range(W):
    for i in range(H):
        if maze[i][j] == '#':
            break
        if i == H - 1:
            index_w.append(j)


for i in range(H):
    flag = True
    for j in range(W):
        if i in index_h:
            flag = False
            break
        if j in index_w:
            continue
        print(maze[i][j], end='')
    if flag:
        print()

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
a = []
b = [0 for i in range(w)]
for i in range(h):
	ai = list(input())
	a.append(ai)
	for j in range(w):
		if b[j] == 0:
			if ai[j] == "#": 
				b[j] = 1
ans = []
for li in a:
	if li == ["." for i in range(w)]:
		h -= 1
	else:
		ans.append(li)
wd = w
ipl = -1
for i in range(w):
	ipl += 1
	if b[i] == 0:
		wd -= 1
		for j in range(h):
			ans[j].pop(ipl)
		ipl -= 1
w = wd
for i in range(h):
	strp = ""
	for j in range(w):
		strp += ans[i][j] 
	print(strp)

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())

amap = []
# 横一列に"#"が含まれている場合はamapにappendする
for _ in range(h):
  a = input()
  if "#" in a:
    amap.append(a)

bmap = []
# 縦一列に"#"が含まれている場合はbmapにappendする
for wid in range(w):
  b = [amap[hei][wid] for hei in range(len(amap))]
  if "#" in b:
    bmap.append(b)

bmap = np.array(bmap)
tbmap = bmap.T

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

Submission status: Accepted

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

B = []
for h in range(H):
    if A[h].count('.') != W:
        B.append(A[h])

for c in range(W-1, -1, -1):
    for r in range(len(B)):
        if B[r][c] != '.':
            break
    else:
        for r in range(len(B)):
            del B[r][c]

for r in range(len(B)):
    print(''.join(B[r]))

Submission status: Accepted

Solution code:
import numpy as np
h,w = map(int,input().split())
lst = []
ans = []
for i in range(h):
    s = input()
    tmp = s.replace('.','')
    if tmp:
        lst.append(list(s))
matrix = np.array(lst)
matrix = matrix.T
for i in range(w):
    s = ''.join(matrix[i])
    tmp = s.replace('.','')
    if tmp:
        ans.append(list(s))
matrix2 = np.array(ans)
matrix2 = matrix2.T
for j in matrix2:
    s = ''.join(j)
    print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

list_h = []
for i in range(len(a)):
    if '#' not in a[i]:
        list_h.append(i)

list_w = []
for i in range(len(a[0])):
    if a[0][i] == '.':
        for j in range(len(a)):
            if a[j][i] == '#':
                break
        else:
            list_w.append(i)

for i in range(len(a)):
    if i not in list_h:
        for j in range(len(a[0])):
            if j not in list_w:
                print(a[i][j], end='')
        else:
            print('')

Submission status: Accepted

Solution code:
#コピペコード
H, W = map(int, input().split())
a = [input() for _ in range(H)]
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 = [list(input()) for _ in range(h)]

tate = [False] * h
yoko = [False] * w

for i in range(h):
    for j in range(w):
        if a[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(a[i][j], end='')
        print()

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
a = [input() for i in range(h)]
x, y = [], []
for i in range(h):
  f = True
  for j in range(w):
    if a[i][j]=="#":
      f = False
  if f:
    y.append(i)
for j in range(w):
  f = True
  for i in range(h):
    if a[i][j]=="#":
      f = False
  if f:
    x.append(j)
for i in range(h):
  if i in y:
    continue
  for j in range(w):
    if j in x:
      continue
    print(a[i][j], end="")
  print()

Submission status: Accepted

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

while b in a:
    a.remove(b)

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

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()

mas = []
for i in range(H):
    row = s()
    if row == '.' * W:
        continue
    mas.append(row)

rmas = ['' for i in range(W)]
for row in mas:
    for i in range(W):
        rmas[i] += row[i]

res = []
for row in rmas:
    if row == '.' * len(mas):
        continue
    res.append(row)

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

Submission status: Accepted

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

# 行チェック
for hi in range(h):
    row = [s for s in input()]
    # 行が全て白だと追加しない
    if row.count('.') == w:
        continue
    else:
        ans.append(row)

# 列チェック
removeindex = []
for wi in range(w):
    blnRem = True
    for row in ans:
        if row[wi] == '#':
            blnRem = False
            break
    if blnRem:
        removeindex.append(wi)

# 表示
for row in ans:
    for i, col in enumerate(row):
        if i in removeindex:
            continue
        print(col, end='')
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
yoko = [True if "#" in a[i] else False for i in range(H)]
b = [list(x) for x in zip(*a)]
tate = [True if "#" in b[i] else False for i in range(W)]
for j in range(H):
    for i in range(W):
        if yoko[j] and tate[i]:
            print(a[j][i], end="")
    if yoko[j]:
        print()

Submission status: Accepted

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

a_list = [list(input()) for i in range(H)]
result = a_list[:]
for i,aa in enumerate(a_list):
    if aa.count('.') == len(aa):
        result[i] = 1
result = [r for r in result if r != 1]

#print(result)
import numpy as np
T_result = np.array(result).T
result2 = T_result.tolist()
for i, aa in enumerate(result2):
    if aa.count('.') == len(aa):
        result2[i] = 1

result2 = [r for r in result2 if r != 1]
for r2 in np.array(result2).T.tolist():
    print(''.join(r2))