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:
# coding: utf-8
import fractions
#N = int(input())

h, w = map(int,input().split())
h_list = []
w_list = []
F = []
for i in range(h):
    l = list(input())
    F.append(l)
    if list(set(l)) == ['.']:
        w_list.append(i)
        
for i in range(w):
    cnt = 0
    for j in range(h):
        if F[j][i] == '.':
            cnt += 1
        else:
            break
    if cnt == h:
        h_list.append(i)
A = []
#print(h_list,w_list)#ここまでOK
for i in range(h):
    if i not in w_list:
        l = []
        for j in range(w):
            if j not in h_list:
                #print(F[i][j])
                l.append(F[i][j])
        
        A.append(l)

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

Submission status: Accepted

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

deleted_w = []
for i in range(H):
  if(all(j == "." for j in grid[i])):
    deleted_w.append(i)

deleted_h = []
for i in range(W):
  line = [ grid[k][i] for k in range(H)]
  if(all(j == "." for j in line)):
    deleted_h.append(i)

for i in range(H):
  if(i in deleted_w):
    continue
  for j in range(W):
    if(j in deleted_h):
      continue
    else:
      print(grid[i][j], end="")
  print("")

Submission status: Accepted

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

for i in range(w):
    t = True
    length = len(a)
    for j in range(length):
        if a[j][i] != '.':
            t = False
            break
    if t:
        for k in a:
            k[i] = 'D'


for i in a:
    for j in i:
        if j != 'D':
            print(j, end='')

    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(H)]
h, w = [True for _ in range(H)], [True for _ in range(W)]
for i in range(H):
  cnt = 0
  for j in range(W):
    if S[i][j] == '.':
      cnt += 1
  if cnt == W:
    h[i] = False
for i in range(W):
  cnt = 0
  for j in range(H):
    if S[j][i] == '.':
      cnt += 1
  if cnt == H:
    w[i] = False
for i in range(H):
  if h[i]:
    T = ""
    for j in range(W):
      if w[j]:
        T = T[:] + S[i][j]
    print(T)

Submission status: Accepted

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

rotate = []
for i in range(w):
    r = [row[i] for row in grid_2]
    rotate.append(r)

rotate_2 = []
for j in rotate:
    if "#" in j:
        rotate_2.append(j)

re_rorate = []
z = len(rotate_2[0])
for i in range(z):
    r_r = [row[i] for row in rotate_2]
    re_rorate.append(r_r)

for i in range(z):
    y = re_rorate[i]
    j ="".join(y)    
    print(j)

Submission status: Accepted

Solution code:
def b_grid_compression():
    import numpy as np
    H, W = [int(i) for i in input().split()]
    A = np.array([list(input()) for _ in range(H)])

    for i in (1, -1):
        A = A[np.any(A == '#', axis=1), :]
        A = np.rot90(A, i)
    return '\n'.join([''.join(row) for row in A])

print(b_grid_compression())

Submission status: Accepted

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

l=[]
for i in range(H):
  x=input()
  # 白いマスのみからなる場合は追加しない
  if x!='.'*W:
    l.append(x)

rm=[]
for i in range(W):
  # フラグ
  f=True
  for j in range(len(l)):
    if l[j][i]=='#':
      f=False

  # 取り除く列の添字を保存しておく
  if f:
    rm.append(i)

a=[]
for x in l:
  for i in rm[::-1]:
    x=x[:i]+x[i+1:]
  a.append(''.join(x))

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
a = ncl(h)

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

for j in range(w):
    flag = True
    for i in range(h):
        if a[i][j] != '.' and a[i][j] != '$':
            flag = False
    
    if flag:
        for i in range(h):
            a[i][j] = '$'

ans = []
for i in range(h):
    ans.append([])
    for j in range(w):
        if a[i][j] != '$':
            ans[i].append(a[i][j])

for i in range(len(ans)):
    if len(ans[i]) != 0:
        print(*ans[i], sep="")

Submission status: Accepted

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

    for h in range(H):
        inp = input()
        if not "#" in inp:
            continue
        strings.append(inp)


    #横の行が消えてるかテスト
    #print("")
    #for s in strings:
    #    print(s)

    delete_row = [False] * W
    for i in range(W):
        if all([string[i]=="." for string in strings]):
            delete_row[i] =True


    #filter
    new_strings = []
    for string in strings:
        temp_s = ""
        for i,c in enumerate(string):
            if not delete_row[i]:
                temp_s = temp_s + c
        new_strings.append(temp_s)
    #print()


    for string in new_strings:
        print(string)











if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    H, W = [int(x) for x in input().split()]
    A = [input().strip() for _ in range(H)]

    ansh = []
    for i, a in enumerate(A):
        if a.count("#") == 0:
            ansh.append(i)

    answ = []
    for i, a in enumerate(zip(*A)):
        if a.count("#") == 0:
            answ.append(i)

    for j in range(H):
        if j in ansh:
            continue
        for i in range(W):
            if i in answ:
                continue
            else:
                print(A[j][i], end="")
        print("")

    
    
    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

grid = [i for i in grid if i.count('#')>0]
c = []
for j in range(w):
    for i in range(len(grid)):
        if grid[i][j]=='#':
            break
    else:
        c.append(j)
for row in grid:
    tmp = ''
    s = 0
    for i in c:
        tmp += row[s:i]
        s = i+1
    tmp += row[s:]
    print(tmp)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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

while 1:
    flag=1
    lst=[]
    for i in range(h):
        tmp=a[i][0]
        if tmp=="#":
            continue
        for j in range(w):
            if tmp==a[i][j]:
                continue
            else:
                break
        else:
            lst.append(i)
            flag=0
    for i in range(len(lst)):
        del a[lst[-1-i]]
        h-=1

    lst=[]
    for i in range(w):
        tmp=a[0][i]
        if tmp=="#":
            continue
        for j in range(h):
            if tmp==a[j][i]:
                continue
            else:
                break
        else:
            lst.append(i)
            flag=0
    # print(lst)
    # print(a)
    for i in range(len(lst)):
        for j in range(h):
            a[j]=a[j][:lst[-1-i]] + a[j][lst[-1-i]+1:]
    w-=len(lst)
    if flag:
        break
for i in a:
    print(i)

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    h, w = MII()
    aa = [IS() for _ in range(h)]
    aa_w = [a for a in aa if '.'*w != a]
    aa_w_t = [''.join(list(a)) for a in zip(*aa_w)]
    w = len(aa_w_t[0])
    aa_w = [a for a in aa_w_t if '.'*w != a]
    aa_w_t = [''.join(list(a)) for a in zip(*aa_w)]
    aa_w_t = [''.join(list(a)) for a in zip(*aa_w)]
    for a in aa_w_t: print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(h):
    x = input()
    
    if x.count(".") != w:
        x = list(x)
        X.append(x)
        
h = len(X)

for i in range(w):
    wrong = 0
    for j in range(h):
        if X[j][i] == ".":
            wrong += 1
            
        if wrong == h:
            for k in range(h):
                X[k][i] = "*"
                
for i in range(h):
    print(("".join(X[i])).replace("*",""))

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
#h, w = list(map(int, input().split()))
a = []
for i in range(h):
    x = input()
    if "#" in x:
        a.append(x)

w90 = []
for i in range(w):
    x = ""
    for j in range(len(a)):
        x += a[j][i]

    if "#" in x:    
        w90.append(x)

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

Submission status: Accepted

Solution code:
def solve():

    H, W = [int(i) for i in input().split()]
    alist = [input() for i in range(H)]

    cols = [False]*H
    rows = [False]*W

    for i in range(H):
        for j in range(W):
            if alist[i][j] == '#':
                cols[i] = True
                rows[j] = True

    for i in range(H):
        if cols[i]:
            for j in range(W):
                if rows[j]:
                    print(alist[i][j], end="")

            print()


if __name__ == "__main__":
    solve()

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 = [input() for i in range(h)]
ans = []
memo_x = []
memo_y = []
for i in range(h):
    cnt = 0
    for j in range(w):
        if a[i][j] == '.':
            cnt += 1
    if cnt == w:
        memo_x.append(i)
for i in range(w):
    cnt = 0
    for j in range(h):
        if a[j][i] == '.':
            cnt += 1
    if cnt == h:
        memo_y.append(i)
for i in range(h):
    if i not in memo_x:
        b = ''
        for j in range(w):
            if j not in memo_y:
                b += a[i][j]
        ans.append(b)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

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

for i in range(H):
    flag = 1
    for j in range(W):
        if l[i][j] == '#':
            flag = 0
    if flag == 1:
        temp_l[i] = 1
        for j in range(W):
            l[i][j] = 0

for i in range(W):
    flag = 1
    for j in range(H):
        if l[j][i] == '#':
            flag = 0
    if flag == 1:
        for j in range(H):
            l[j][i] = 0


for i in range(H):
    for j in range(W):
        if temp_l[i] == 0:
            if not l[i][j] == 0:
                print(l[i][j], end='')
    if temp_l[i] == 0:
        print('')

Submission status: Accepted

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

delete_column = [True]*w
delete_row = [True]*h
for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      delete_column[j] = False
      delete_row[i] = False
for i in range(h):
  if not delete_row[i]:
    ans = ''
    for j in range(w):
    	if not delete_column[j]:
          ans += a[i][j]
    print(ans)

Submission status: Accepted

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

masu=[]
for i in range(h):
    gyou=list(input())
    if gyou!=["."]*w:
        masu.append(gyou)
        
def rotate(masu):
    m=len(masu)
    n=len(masu[0])
    rotatemasu=[]
    for i in range(n):
        gyou=[]
        for j in range(m):
                gyou.append(masu[m-j-1][i])
        if gyou!=["."]*m:
            rotatemasu.append("".join(gyou))
        
    return rotatemasu
for i in range(4):
    masu=rotate(masu)
for i in masu:
    print(i)

Submission status: Accepted

Solution code:
p,q= input().split()
a,b =(int(p), int(q))
a_list = []
count_row = 0
b_h ='.'*b

for i in range(a):
    c = input()
    
    if c == b_h:
        count_row+=1
    else:
        a_list.append(c)

ans_list=[]
for i in range(b):
    count_clm = 0
    
    for j in range(a-count_row):
        if a_list[j][i] == '.':
            count_clm+=1
    
    
        if count_clm == (a-count_row):        
            ans_list.append(i)



for j in range(a-count_row):
    total=''
    for i in range(b):
        if i in ans_list:
            ds = 0
        else:
            total +=a_list[j][i]
            
    print(total)

Submission status: Accepted

Solution code:
def solve():

    H, W = [int(i) for i in input().split()]
    alist = [input() for i in range(H)]

    cols = [False]*H
    rows = [False]*W

    for i in range(H):
        for j in range(W):
            if alist[i][j] == '#':
                cols[i] = True
                rows[j] = True

    for i in range(H):
        if cols[i]:
            for j in range(W):
                if rows[j]:
                    print(alist[i][j], end="")
            print()


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
answer = []
for _ in range(H):
    a = list(input())
    if("#" in a): A.append(a)


for a in list(zip(*A)):
    if("#" in a): answer.append(a)

for result in list(zip(*answer)): print("".join(result))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[]
for _ in range(H):
    a=list(input())
    if("#" in a):
        A.append(a)
answer=[]
for i in range(W):
    tmp=[]
    hantei=True
    for a in A:
        if(a[i]=="#"):
            hantei=False
        tmp.append(a[i])
    if(hantei==False):
        answer.append(tmp)

result = list(zip(*answer))
for r in result:
    print("".join(r))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for _ in [0]*h ]
b=[[i[j] for i in a] for j in range(w)]
H,W=[],[]
for i in range(h):
  if a[i]==['.']*w:
    H.append(i)
for j in range(w):
  if b[j]==['.']*h:
    W.append(j)
a=[''.join([a[i][j] if not j in W else '' for j in range(w)]) if not i in H else 0 for i in range(h)]
for i in range(h):
  if type(a[i])!=int:
    print(a[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():

    H, W = map(int, input().split())
    alist = [input() for i in range(H)]

    cols = [False] * H
    rows = [False] * W

    for i in range(H):
        for j in range(W):
            if alist[i][j] == '#':
                cols[i] = True
                rows[j] = True

    for i in range(H):
        if cols[i]:
            for j in range(W):
                if rows[j]:
                    print(alist[i][j], end="")

            print()


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))  #リスト
A = list(input() for i in range(H)) #スペース抜きの複数行
#A = [input() for _ in range(H)]

B = [False] * H
C = [False] * W

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

for i in range(H):
	if B[i]:
		for j in range(W):
			if C[j]:
				print(A[i][j], end = '')
		print()

Submission status: Accepted

Solution code:
inputs = [s.strip() for s in open(0).readlines()]
import numpy as np
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, rows in zip(range(h), grid):
            for j, val in zip(range(w), rows):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, rows)) for rows in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

h, w = map(int, inputs[0].split())
grid = Grid([s.strip() for s in inputs[1:]]).grid
grid = grid[:, ~np.all(grid == '.', axis=0)]
grid = grid[~np.all(grid == '.', axis=1), :]
print(*[''.join(map(str, row)) for row in grid], sep='\n')

Submission status: Accepted

Solution code:
#ABC-107-B
def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        row = list(input())
        grid.append(row)

    for i in reversed(range(H)):
        if not "#" in grid[i]:
            del grid[i]
            H -= 1

    for j in reversed(range(W)):
        flag = True
        for i in reversed(range(H)):
            if grid[i][j] == "#":
                flag = False
                break
        if flag == True:
            for i in range(H):
                del grid[i][j]
    for row in grid:
        print("".join(row))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
h_w_list = [list(input()) for i in range(h)]
h_li = []
w_li = []
for i in range(h):
    if "#" in h_w_list[i]:
        h_li.append(i)
for j in range(w):
    if "#" in [h_w_list[k][j] for k in range(h)]:
        w_li.append(j)
for i in h_li:
    for j in w_li:
        print(h_w_list[i][j], end="")
    print()

Submission status: Accepted

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

cnt=0
while cnt<H:
    if a[cnt]=='.'*W:
        H-=1
        del a[cnt]
    else:
        cnt+=1

cnt=0
while cnt<W:
    for s in a:
        if s[cnt]=='#':
            cnt+=1
            break
        elif s==a[H-1]:
            W-=1
            for i in range(H):
                a[i]=a[i][:cnt]+a[i][cnt+1:]

            
for s in a:
    print(s)

Submission status: Accepted

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

row = [False]*h
cow = [False]*w

for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      row[i] = True
      cow[j] = True
      
for i in range(h):
  if row[i]: 
    for j in range(w):
      if cow[j]:
        print(a[i][j], end="")
 
    print()

Submission status: Accepted

Solution code:

def Grid_Compression(h , w , ahl):

    ans = []
    hcount = []
    wcount = []

    for n in range(w):
        flag = True
        for m in range(h):
            if ahl[m][n] == "#":
                flag = False
        if flag == False:
            wcount.append(n)

    for n in range(h):
        flag = True
        for m in range(w):
            if ahl[n][m] == "#":
                flag = False
        if flag == False:
            hcount.append(n)

    for nh in hcount:
        ansli = []
        for nw in wcount:
            ansli.append(ahl[nh][nw])
        ans.append(ansli)

    return ans

def main():
    h , w = map(int , input().split())
    ahl = [list(str(input())) for i in range(h)]
    ans = Grid_Compression(h , w , ahl)
    for i in ans:
        pr = ""
        for w in i:
            pr += w
        print(pr)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

grid=[[0 for j in range(w)] for i in range(h)]
tate=[]
ans=[]
for i in range(h):
    b=input()
    for j in range(w):
        grid[i][j]=b[j]

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

if len(tate)>1:
    tate=[n-i for i,n in enumerate(tate)]

for j in tate:
    for i in grid:
        i.pop(j)

for i in grid:
    if i.count('.')!=len(i):
        ans.append(i)

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

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  h,w = map(int,input().split())
  rec = [list(input()) for _ in range(h)]
  #print(rec)
  flag = False
  # yoko
  for i in range(h):
    for j in range(w):
      if rec[i][j] == '.':
        flag = True
        pass
      else:
        flag = False
        break
    if flag:
      for r in range(w):
        rec[i][r] = 'd'
  #print(rec)
  
  
  # tate
  for j in range(w):
    for i in range(h):
      if rec[i][j] == '.' or rec[i][j] == 'd':
        flag = True
        pass
      else:
        flag = False
        break
    if flag:
      for r in range(h):
        rec[r][j] = 'd'
        
  #print(rec)
  
  
  for i in range(h):
    new = ""
    for j in range(w):
      if rec[i][j] != 'd':
        new += rec[i][j]
    if len(new) != 0:print(new)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
h, w = [int(x) for x in input().split()]
masu = [input() for i in range(h)]
for i in range(h):
  for j in range(w):
    if all([masu[i][k] == '.' for k in range(w)]):
      break
    elif all([masu[k][j] == '.' for k in range(h)]):
      continue
    else:
      print(masu[i][j], sep='', end='')
  else:
    print('')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[]
for i in range(n):
  t=input()
  if '#' in t:
    s.append(t)
s2=[list(x) for x in zip(*s)]
s3=[]
for i in range(m):
  if '#' in s2[i]:
    s3.append(s2[i])
s4=[list(x) for x in zip(*s3)]
for i in s4:
  print("".join(map(str,i)))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
v = [g for g in G if g.count('.') != W]
for i in reversed(range(W)):
    chk = True
    for vv in v:
        if vv[i] == '#':
            chk = False
            break
    if chk:
        for vv in v:
            vv.pop(i)
for vv in v:
    print(''.join(vv))

Submission status: Accepted

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

delete_y=[]
for y in range(H):
    count=0
    for x in range(W):
        if a[y][x]=='.':
            count+=1
    if count==W:
        delete_y.append(y)

delete_x=[]
for x in range(W):
    count=0
    for y in range(H):
        if a[y][x]=='.':
            count+=1
    if count==H:
        delete_x.append(x)
#print(delete_x, delete_y)

for y in range(H):
    if y not in delete_y:
        row=''
        for x in range(W):
            if x not in delete_x:
                row+=(a[y][x])
        print(row)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [input() for _ in range(h)]
check_h = [True]*h
check_w = [True]*w
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            break
    else:
        check_h[i] = False
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            break
    else:
        check_w[i] = False

ans = []
for i in range(h):
    if check_h[i]:
        s = ''
        for j in range(w):
            if check_w[j]:
                s += a[i][j]
        ans.append(s)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
H,W = [int(x) for x in input().split()]
a = []
H2 = 0
W2 = 0
count = [0] * W
for i in range(H):
    l = list(input())
    if l != ["."]*W:
        a.append(l)
        H2 += 1
for i in range(W):
    flag = 1
    for j in range(H2):
        if a[j][i] != ".":
            flag = 0
            break
    count[i] = flag
for i in range(H2):
    an = []
    for j in range(W):
        if count[j] == 0:
            an.append(a[i][j])
    print("".join(an))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[]
for i in range(n):
  t=input()
  if '#' in t:
    s.append(t)
s2=[list(x) for x in zip(*s)]
s3=[]
for i in range(m):
  if '#' in s2[i]:
    s3.append(s2[i])
s4=[list(x) for x in zip(*s3)]
for i in s4:
  print("".join(map(str,i)))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for _ in range(H):
    i = list(input())
    if '#' in i:
        a.append(i)
ans = zip(*[i for i in zip(*a) if '#' in i])
for s in ans:
    print(*s, sep='')

Submission status: Accepted

Solution code:
import numpy as np
H,W = map(int,input().split())
grid = []
ans = []
for i in range(H):
    h = list(input())
    if "#" in h:
        grid.append(h)
grid = np.array(grid)
grid = grid.T
for i in range(len(grid)):
    w = grid[i]
    if "#" in w:
        ans.append(w)
ans = np.array(ans).T
for i in ans:
    print("".join(i))

Submission status: Accepted

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

def main():
    H, W = map(int, input().split())
    a = [input() for _ in range(H)]
    a = [w for w in a if w.count('#') > 0]

    ans = [''] * len(a)
    for i in range(W):
        isOK = False
        for s in a:
            if s[i] == '#':
                isOK = True
                break
        if isOK:
            for j, s in enumerate(a):
                ans[j] += s[i]
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    H, W = map(int, input().split())
    a = []
    for _ in range(H):
        w = input()
        if w.count('#') > 0:
            a.append(w)
    ans = [''] * len(a)
    for i in range(W):
        isOK = False
        for s in a:
            if s[i] == '#':
                isOK = True
                break
        if isOK:
            for j, s in enumerate(a):
                ans[j] += s[i]
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
A = []
for i in range(N):
    B = list(input())
    if "#" in B: 
        A.append(B)
    else:
        pass
after_A = []
Fafter_A = []
for i in range(M):
    C = ""
    for j in range(len(A)):
        C += A[j][i]
    after_A.append(C)
for i in range(M):
    if "#" in after_A[i]: 
        Fafter_A.append(after_A[i])
    else:
        pass
for i in range(len(A)):
    D = ""
    for j in range(len(Fafter_A)):
        D += Fafter_A[j][i]
    print(D)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x, y = [], []
for i in range(h):
    c = 0
    for j in range(w):
        if a[i][j] == "#":
            c = 1
            break
    if c == 0:
        x.append(i)
for i in range(w):
    c = 0
    for j in range(h):
        if a[j][i] == "#":
            c = 1
            break
    if c == 0:
        y.append(i)
for i in range(h):
    if not i in x:
        for j in range(w):
            if not j in y:
                print(a[i][j], end = "")
        print()

Submission status: Accepted

Solution code:
import sys

def resolve():
    H, W = map(int, input().split(" "))
    cols = [input() for i in range(H)]
    skip_cols = []
    skip_rows = []
    for i, col in enumerate(cols):
        if col.replace(".", "") == "":
            skip_cols.append(i)
    for j in range(W):
        for col in cols:
            if col[j] == "#":
                break
        else:
            skip_rows.append(j)
    for i, col in enumerate(cols):
        if i in skip_cols:
            continue
        for j, c in enumerate(col):
            if j in skip_rows:
                continue
            sys.stdout.write(c)
        sys.stdout.write("\n")
    return

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import numpy as np

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

def delete_rows(A):
  del_list = []
  for i, a in enumerate(A):
    if (a == '.').all():
      del_list.append(i)
  return np.delete(A, del_list, axis=0)


A = delete_rows(delete_rows(A).T).T
for a in A:
  print(''.join(a))