Problem:


Score : 200 points

Problem Statement

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

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

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

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

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

###
###
.##

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

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

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

Sample Input 3

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

Sample Output 3

#

Sample Input 4

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

Sample Output 4

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



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


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

Submission status: Accepted

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

for i in range(h):
  j = list(input())
  if '#' in j:
    a.append(j)
    
ans = zip(*[i for i in zip(*a) if '#' in i])

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

Submission status: Accepted

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

a1 = []
for h_i in range(h):
    if "#" in a[h_i]:
        a1.append(a[h_i])

a2 = []
for w_i in range(w):
    for h_i in range(len(a1)):
        if a1[h_i][w_i] == "#":
            break
    else:
        a2.append(w_i)

for i in range(len(a2)):
    a2[i] -= i

for ele in a2:
    for h_i in range(len(a1)):
        a1[h_i].pop(ele)

for h_i in range(len(a1)):
    print("".join(a1[h_i]))

Submission status: Accepted

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

A_int = []
for a in A:
  temp = []
  for i in range(W):
    if a[0][i] == '.':
      temp.append(0)
    else:
      temp.append(1)
  if sum(temp)>0:
    A_int.append(temp)

import numpy as np
A = np.array(A_int)
del_columns=[]
for i in range(len(np.all(A==0, axis=0))):
  if np.all(A==0, axis=0)[i]==True:
    del_columns.append(i)
A_del = np.delete(A, del_columns, axis=1)

for i in range(A_del.shape[0]):
  ans=""
  for j in range(A_del.shape[1]):
    if A_del[i][j]==0:
      ans += "."
    else:
      ans += "#"
  print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
maplist = []
h2 = h
for i in range(h):
    k = [x for x in input()]
    for j in range(len(k)):
        if k[j] == "#":
            maplist.append(k)
            break
        if j == len(k)-1:
            h2 -= 1
deletelist = []
for i in range(w):
    for j in range(h2):
        if maplist[j][i] == "#":
            break
        if j == h2-1:
            deletelist.append(i)
deletelist = reversed(deletelist)
for i in deletelist:
    for j in range(h2):
        maplist[j].pop(i)
for i in range(h2):
    print("".join(maplist[i]))

Submission status: Accepted

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

for i in a:
    for j in range(W):
        if i[j] == '#':
            jud[j] += 1
        else:
            continue

b = [i for i in a if '#' in i]

for i in range(len(b)):
    ans = ''
    for j in range(W):
        if jud[j] != 0:
            ans += b[i][j]
        else:
            continue
    print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
L = [list(input()) for _ in range(H)]
L1 = [x for x in L if "#" in x]
L2 = [x for x in zip(*L1) if "#" in x]
for t in zip(*L2):
    print(''.join(t))

Submission status: Accepted

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

L1 = list(filter(lambda x: ''.join(x) != '.' * W, L))
L2 = list(filter(lambda x: x.count('.') != len(L1), list(zip(*L1))))
for t in list(zip(*L2)):
    print(''.join(t))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [list(input()) for i in range(H)]
A_line = ['.'] * W
de_row = []
de_column = []
s = 0
t = 0
ind = 0
for a in A:
    if a == A_line:
        de_column.append(ind)
    ind += 1
for d in de_column:
    del A[d-s]
    s += 1

for i in range(W):
    flag = 0
    for j in range(len(A)):
        if A[j][i] == '.':
            flag += 1
            if flag == len(A):
                de_row.append(i)
            continue
        else:
            break

for d in de_row:
    for i in range(len(A)):
        del A[i][d-t]
    t += 1
for a in A:
    print(''.join(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
h, w = map(int, input().split())
# h * w個の文字を入力
a = [[0]*w]*h
for i in range(h):
    a[i] = list(input())

# 空行削除
a = [ai for ai in a if "".join(ai) != "."*w]

# 空列削除, atに転置させたresultを詰め込む
at = []
for aj in zip(*a):
    if "".join(aj) != "."*len(aj):
        at.append(aj)

# 結果の出力
for ai in zip(*at):
    print("".join(ai))

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

h, w = na()
mas = []
li = []
for i in range(h):
    col = input()
    if "#" in col:
        mas.append(col)
for i in range(w):
    for j in range(len(mas)):
        if mas[j][i] == ".":
            if j == len(mas) - 1:
                li.append(i)
            continue
        else:
            break
for i in range(len(mas)):
    ans = ""
    for j in range(w):
        if j not in li:
            ans += mas[i][j]
    print(ans)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = []
for i in range(H):
    a = list(input())
    if a.count('.') == W:
        H -= 1
        continue
    A.append(a)

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

for i in range(H):
    for j in range(W):
        if j in skipcol: 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)]
memo = []
b = []
for i in range(H):
  if "#" in a[i]:
    memo.append(i)
for x in memo:
  b.append(a[x])
memo = []
d = []
for c in zip(*b):
  d.append(c)
for i in range(W):
  if "#" in d[i]:
    memo.append(i)
e = []
for x in memo:
  e.append(d[x])
for r in zip(*e):
  print("".join(r))

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.empty(0,dtype=np.unicode)
for i in range(h):
    a = np.append(a,[x for x in input()])

a = np.reshape(a,(h,w))
a = a[:,np.any(a == '#',axis=0)]
a = a[np.any(a == '#',axis=1)]

a = a.tolist()
for i in a:
    print("".join(i))

Submission status: Accepted

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

for i in range(h-1,-1,-1):
    if "#" not in l[i]:
        del l[i]
z = list(zip(*l))

for i in range(len(z)-1,-1,-1):
    if "#" not in z[i]:
        for j in range(len(l)):
            del l[j][i]
            
for i in range(len(l)):
    print("".join(l[i]))

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=np.array([list(input()) for i in range(h)])
c=0
for j in range(h,0,-1):
    if all([k=='.' for k in a[j-1,:]]):
        a=np.delete(a,j-1,0)
        c+=1
for l in range(w,0,-1):
    if all([n=='.' for n in a[:,l-1]]):
        a=np.delete(a,l-1,1)
for m in range(h-c):
    print(''.join(a[m,:]))

Submission status: Accepted

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

updated = True
while updated:
    updated = False
    newA = []
    for i in range(len(A)):
        if len(set(A[i])) == 1 and A[i][0] == '.':
            updated = True
        else:
            newA.append(A[i])
    A = newA
    newA = []
    for j in range(len(A[0])):
        tmp = [A[i][j] for i in range(len(A))]
        if len(set(tmp)) == 1 and A[0][j] == '.':
            updated = True
        else:
            newA.append(tmp)
    A = [['.' for j in range(len(newA))] for i in range(len(newA[0]))]
    for i in range(len(newA)):
        for j in range(len(newA[i])):
            A[j][i] = newA[i][j]
#     print()
#     for i in range(len(A)):
#         print("".join(A[i]))
# print()

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

Submission status: Accepted

Solution code:
import numpy as np
H, W = list(map(int, input().split()))
l = []
for h in range(H):
    l.append(list(input()))
nl = np.array(l)

t = np.all(nl == ".", axis=1)
dl = []
for i, f in zip(range(len(t) + 1), t):
    if f:
        dl.append(i)
nl = np.delete(nl, dl, axis=0)

dl = []
t = np.all(nl == ".", axis=0)
for i, f in zip(range(len(t) + 1), t):
    if f:
        dl.append(i)
nl = np.delete(nl, dl, axis=1)

for s in nl:
    print("".join(s))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = []
for i in range(h):
  _s = input()
  if '#' in _s:
    s.append(_s)
    
deletes = []
for j in range(w):
  for i in range(len(s)):
    if s[i][j] == '#':
      break
  else:
    deletes.append(j)
    
for i in range(len(s)):
  out = ''
  for j in range(len(s[i])):
    if not j in deletes:
      out += s[i][j]
  print(out)

Submission status: Accepted

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

cnt = 0
rb = [x.count('.') == w for x in a]
for i in range(len(rb)):
    if rb[i] is True:
        del a[i-cnt]
        cnt += 1
cnt = 0
cb = [x.count('.') == len(a) for x in zip(*a)]
for i in range(len(cb)):
    if cb[i] is True:
        for j in range(len(a)):
            del a[j][i-cnt]
        cnt += 1

for x in a:
    print(*x, sep='')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[[i for i in input()] for j in range(h)]
B=[a for a in A if "#" in a]
C=[b for b in zip(*B) if "#" in b]
for c in zip(*C):
  print(*c,sep="")

Submission status: Accepted

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

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

b = []

for i in range(h):
    if any(c == '#' for c in a[i]):
        b.append(a[i])

#print(b)

c = []
for i in range(w):
    s = ''
    for j in range(len(b)):
        s += b[j][i]
    c.append(s)

#print(c)
d = []

for i in range(len(c)):
    if any(c == '#' for c in c[i]):
        d.append(c[i])

#print(d)

e = []
for i in range(len(d[0])):
    s = ''
    for j in range(len(d)):
        s += d[j][i]
    e.append(s)

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

    while True:
        find = False
        for i in G:
            if all(j == "." for j in i):
                G.remove(i)
                find = True
                break
        for i in range(len(G[0])):
            b = True
            for j in G:
                if j[i] != ".":
                    b = False
                    break
            if b:
                find = True
                for j,k in enumerate(G):
                    G[j] = k[:i] + k[i+1:]
                break
        if not find:
            for i in G:
                print(i)
            return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = []
for i in range(h):
  s = input()
  if '#' in s:
    grid.append(list(s))
h = len(grid)

for j in range(w)[::-1]:
  skip = False
  for i in range(h):
    if grid[i][j] == '#':
      skip = True
      break
  if not skip:
    for i in range(h):
      grid[i][j] = ''

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

Submission status: Accepted

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

a = [list(input()) for _ in range(H)]
a_copy = a.copy()
for cs in a_copy:
    for c in cs:
        if c == '#':
            break
    else:
        a.remove(cs)

a_copy = copy.deepcopy(a)
count = 0
for row in range(len(a_copy[0])):
    for line in range(len(a_copy)):
        if a_copy[line][row] == '#':
            break
    else:
        for line in range(len(a_copy)):
            del a[line][row - count]
        count += 1

for cs in a:
    for c in cs:
        print(c, end='')
    print()

Submission status: Accepted

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

tmp = []
for i in range(H):
    row = input()
    if '#' in row:
        tmp.append(row)

res = [''] * len(tmp)
for col in zip(*tmp):
    if '#' in col:
        for j in range(len(tmp)):
            res[j] += col[j]

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

Submission status: Accepted

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

alist1 = []
for row in alist:
  if '#' in row:
    alist1.append(row)

alist2 = []
for row in zip(*alist1):
  if '#' in row:
    alist2.append(row)

for row in zip(*alist2):
  print(''.join(row))

Submission status: Accepted

Solution code:
#6974436 ponestrellaさんのコード

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 = [''] * 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:
import sys;from numpy import*;h,w=input().split();a=array([list(input())for _ in range(int(h))]);savetxt(sys.stdout.buffer,a[any(a=="#",axis=1)][:,any(a=="#",axis=0)],fmt="%s",delimiter="")

Submission status: Accepted

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

for i in range(H):
        all_white = True
        for j in range(W):
                if a[i][j] == '#':
                        all_white = False
        if all_white == False:
                b.append(a[i])
H = len(b)

for j in range(W):
        all_white = True
        for i in range(H):
                if b[i][j] == '#':
                        all_white = False
        if all_white == True:
                for i in range(H):
                        b[i][j] = ' '    

for i in range(H):
        for j in range(W):
                if b[i][j] != ' ':
                        print(b[i][j], end = '')
        print(end = '\n')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
board = []
checkColumn = [False]*h
checkRow = [False]*w
for i in range(h):
    board.append(input())

for i in range(h):
        for j in range(w):
            if board[i][j] == "#":
                checkColumn[i] = True
                checkRow[j] = True
for i in range(h):
    if checkColumn[i]:
        for j in range(w):
            if checkRow[j]:
                print(board[i][j],end="")
        print()

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append([a for a in input()])
    removeR = []
    for i in range(H):
        if all(A[i][j] == "." for j in range(W)):
            removeR.append(i)
    removeC = []
    for j in range(W):
        if all(A[i][j] == "." for i in range(H)):
            removeC.append(j)
    B = []
    for i in range(H):
        if i not in removeR:
            temp = []
            for j in range(W):
                if j not in removeC:
                    temp.append(A[i][j])
            B.append(temp)

    return B

if __name__ == '__main__':
    B = main()
    for i in range(len(B)):
        print("".join(B[i]))

Submission status: Accepted

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

for i in range(H):
    line = input()
    if line.count('.') == W:
        H -= 1
        continue
    else:
        lines.append(line)

for i in range(W):
    string =''
    for j in range(H):
        string += lines[j][i]
    linesT.append(string)

lines = []
for i in range(W):
    if linesT[i].count('.') == H:
        W -= 1
        continue
    else:
        lines.append(linesT[i])

ans = []
for i in range(H):
    string = ''
    for j in range(W):
        string += lines[j][i]
    ans.append(string)

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

Submission status: Accepted

Solution code:
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    H, W = list(map(int, sys.stdin.readline().split()))
    L = [list(list(sys.stdin.readline().rstrip())) for i in range(H)]

    L = list(filter(lambda a: any(x == "#" for x in a), L))
    L = list(filter(lambda a : any(x == "#" for x in a), zip(*L)))
    for l in zip(*L):
        print("".join(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n,m = map(int,input().split())
out = []
for i in range(n):
    s = list(input())
    if any(c=="#" for c in s):
        out.append(s)

out = np.array(out).T
# print(out)
out2=[]
for i in range(m):
    if any(c=="#" for c in out[i]):
        out2.append(out[i])

out2=np.array(out2).T
# print(out2)

for line in out2:
    for i in range(len(line)-1):
        print(line[i],end="")
    print(line[-1])

Submission status: Accepted

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

a=[]
for _ in range(h):
    # 追加の前に、行での除去を行う
    s=input()
    if not s.count(".")==w:
        a.append(list(s))
h=len(a)

j=0
while(j<len(a[0])):
    white_count=0
    for i in range(h):
        if a[i][j]=="#":
            j+=1
            break
        else:
            white_count+=1
    if white_count==h:
        for i in range(h):
            a[i]=a[i][:j] +a[i][j+1:]

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

Submission status: Accepted

Solution code:
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    H, W = list(map(int, sys.stdin.readline().split()))
    L = [list(list(sys.stdin.readline().rstrip())) for i in range(H)]

    NL = []
    for l in L:
        if "#" in l:
            NL.append(l)

    # リストの転置
    # https://note.nkmk.me/python-list-transpose/
    L = list(zip(*NL))
    NL2 = []
    for l in L:
        if "#" in l:
            NL2.append(l)

    # もとに戻す
    L = list(zip(*NL2))
    for l in L:
        print("".join(l))

Submission status: Accepted

Solution code:
import sys
h,w=map(int,input().split())
l1=[]
l2=[]
a=[]
for i in range(h):
    l1.append(list(map(str,input())))
for i in range(len(l1)):
    if set(l1[i])!={'.'}:
        l2.append(l1[i])
for k in range(len(l2[0])):
    c=0
    for i in range(len(l2)):
        if l2[i][k]=='.':
            c+=1
            continue
        else:
            break
    if c!=len(l2):
        a.append(k)
for i in range(len(l2)):
    b=''
    for k in a:
        b+=l2[i][k]
    print(b)

Submission status: Accepted

Solution code:
def is_horizontal_same(s):
    for j in range(0, len(s)):
        if s[j] != ".":
            return False
    return True


def is_vertical_same(str_list, i):
    for j in range(0, len(str_list)):
        if str_list[j][i] != ".":
            return False
    return True


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

    str_list = []
    for i in range(0, h):
        str_list.append(input())

    while True:
        is_completed = True

        same_line_indexes = []
        for i in range(0, len(str_list)):
            if is_horizontal_same(str_list[i]):
                same_line_indexes.append(i)
                is_completed = False
        popped_cnt = 0
        for i, v in enumerate(same_line_indexes):
            str_list.pop(v - popped_cnt)
            popped_cnt += 1

        same_vertical_line_indexes = []
        for i in range(0, len(str_list[0])):
            if is_vertical_same(str_list, i):
                same_vertical_line_indexes.append(i)
                is_completed = False
        popped_cnt = 0
        for i, v in enumerate(same_vertical_line_indexes):
            for j in range(0, len(str_list)):
                org_str = str_list[j]
                str_list[j] = org_str[:v - popped_cnt] + org_str[v - popped_cnt + 1:]
            popped_cnt += 1

        if is_completed:
            break

    for i, v in enumerate(str_list):
        print(v)


main()

Submission status: Accepted

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

black_mark_row = set()
black_mark_col = set()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            black_mark_row.add(i)
            black_mark_col.add(j)

for i in range(h):
    flag_line = False
    for j in range(w):
        if i in black_mark_row and j in black_mark_col:
            print(a[i][j],sep="",end="")
            flag_line = True
    if flag_line:
        print()

Submission status: Accepted

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

del_col_idxs = set()
for i in range(w):
    for j in range(h):
        if a[j][i] == "#":
            break
    else:
        del_col_idxs.add(i)

for i in range(len(ans)):
    for j in range(w):
        if not j in del_col_idxs:
            print(ans[i][j],sep="",end="")
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
matrix = [input() for i in range(H)]
matrix2 = [[i[j] for j in range(W)] for i in matrix if i != ''.join(['.'] * W)]
new_H = len(matrix2)
remove_col = ''.join(['.'] * new_H)
i = 0
while i < len(matrix2[0]):
  if ''.join([row[i] for row in matrix2]) == remove_col:
    list(map(lambda x: x.pop(i), matrix2))
  else:
    i += 1
 
print('\n'.join([''.join(i) for i in matrix2]))

Submission status: Accepted

Solution code:
H, W = [int(x) for x in input().split()]
a = [x for x in [input() for _ in range(H)] if '#' in x]
w = 0
while w < len(a[0]):
  for h in range(len(a)):
    if a[h][w]=='#':
      w += 1
      break
  else:
    for h in range(len(a)):
      a[h] = a[h][:w] + a[h][w+1:]

for h in range(len(a)):
  print(a[h])

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
sij=[[x for x in input()] for _ in range(h)]
sijd=[line for line in sij if "#" in line]
sijdd=zip(*[line for line in zip(*sijd) if "#" in line])
for line in sijdd:
    print("".join(line))

Submission status: Accepted

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

    A = [list(input()) for i in range(H)]

    B = []
    for a in A:
        if a.count('#') != 0:
            B.append(a)
    
    B = list(map(list, zip(*B)))
    C = []
    for b in B:
        if b.count('#') != 0:
            C.append(b)

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

    for c in C:
        print(*c, sep='')



main()

Submission status: Accepted

Solution code:
def solve():
    h, w = map(int, input().split())
    grid = list(input() for _ in range(h))
    new_grid = []
    white_columns = set([i for i in range(w)])
    for line in grid:
        if line != "." * w:
            new_grid.append(line)
            white_columns &= set([i for i, c in enumerate(line) if c == "."])
    if white_columns:
        for line in new_grid:
            new_line = "".join([c for i, c in enumerate(line) if i not in white_columns])
            print(new_line)
    else:
        print("\n".join(new_grid))


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:

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

Bs = [x for x in As if "#" in x]
Cs = list(zip(*Bs))
Ds = [x for x in Cs if "#" in x]
ret = list(zip(*Ds))

for x in ret:
    print(*x, sep="")

Submission status: Accepted

Solution code:

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

Bs = []
for a in As:
    if "#" in a:
        Bs.append(a)

Cs = list(map(list, zip(*Bs)))
Ds = []
for c in Cs:
    if "#" in c:
        Ds.append(c)

ret = list(map(list, zip(*Ds)))
for x in ret:
    print(*x, sep="")

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
grid=np.empty((h,w),dtype="<U")
for i in range(h):
    s=list(input())
    grid[i]=s

del_row=[]
del_col=[]
for i in range(h):
    if all(grid[i]=="."):
        del_row.append(i)
for j in range(w):
    if all(grid[:,j]=="."):
        del_col.append(j)
        
grid=np.delete(grid, del_row, 0)
grid=np.delete(grid, del_col, 1)

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

Submission status: Accepted

Solution code:
import math
import sys
from itertools import accumulate
from functools import reduce
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    h,w = map(int, sys.stdin.readline().split())
    a = [list(list(sys.stdin.readline().rstrip())) for i in range(h)]
    c = [list(row) for row in zip(*a)]
    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))

    # #zip exercize
    # l = [[1, 2, 3], [4, 5, 6]]
    # l_t = list(zip(*l))
    # print(l_t)

Submission status: Accepted

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

A = []
for i in range(H):
  S = input()
  if S.count(".") != W:
    A.append(S)

c = zip(*[i for i in zip(*A) if "#" in i])
for d in c:
  print("".join(d))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
wl=[]
for i in range(h):
    wf=0
    for j in range(w):
        if l[i][j]=='.':
            wf+=1
    if wf<w:
        wl.append(i)
    
hl=[]
for i in range(w):
    hf=0
    for j in range(h):
        if l[j][i]=='.':
            hf+=1
    if hf<h:
        hl.append(i)
for i in wl:
    for j in hl:
        print(l[i][j],end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
arr = [list(input()) for i in range(h)]
 
arr = [x for x in arr if "#" in x]
arr = list(zip(*arr)) # transpose
arr = [x for x in arr if "#" in x]
arr = list(zip(*arr)) # transpose
for x in arr:
  print("".join(x))

Submission status: Accepted

Solution code:
# -*-coding: utf-8 -*-
H, W = map(int, input().split())
a = []
for i in range(H): # 文字列は扱いにくいので'.' -> 0, '#' -> 1と置換
    a.append(list(input()))
    a[i] = [0 if x == '.' else 1 for x in a[i]]

# まずは行を取り除く
new_a = []
for i in range(H):
    if sum(a[i]) != 0:
        new_a.append(a[i])

# print(2, new_a)

# 転置
new_a_t = [list(x) for x in zip(*new_a)]
# print(3, new_a_t)
# 転置した行を取り除く(元の配列の列を取り除くのと同じ)
pre_ans = []
for i in range(W):
    if sum(new_a_t[i]) != 0:
        pre_ans.append(new_a_t[i])

# print(4, pre_ans)

# 転置
pre_ans = [list(x) for x in zip(*pre_ans)]

# print(5, pre_ans)

for i in range(len(pre_ans)):
    pre_ans[i] = ['#' if x == 1 else '.' for x in pre_ans[i]]
    # print(i, pre_ans[i])
    print("".join(pre_ans[i]))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
a = [list(input()) for i in range(H)]
b = []
c = []
for y in range(H):
  if "#" in a[y]:
    b.append(a[y])
for row in zip(*b):
  if "#" in row:
    c.append(row)
for row in zip(*c):
  print("".join(row))

Submission status: Accepted

Solution code:
import numpy as np
h,w=input().split()
h,w=int(h),int(w)
x3=[]
for i in range(h):
    x1=input()
    if x1 !=  w*".":
        x3.append(list(x1))

x3=np.array(x3).T.tolist()
x4=[]
for i in range(w):
    if x3[i] != ["." for i in range(len(x3[i]))]:
        x4.append(x3[i])

x4=np.array(x4).T.tolist()
for i in range(len(x4)):
    for j in range(len(x4[0])):
        print(x4[i][j],end="")
    print()