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=[list(input()) for i in range(h)]
answ=[]
ansh=[]
for i in range(h):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(w):
  if not all([A[i][j]=="." for i in range(h)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("\n")

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
mat = []
for _ in range(H):
    a = list(input())
    ca = [0 if i == '.' else 1 for i in a]
    mat.append(ca)
amat = np.array(mat)

mask1 = []
for i in range(H):
    if np.sum(amat[i]) != 0:
        mask1.append(i)
amat1 = amat[mask1]

mask2 = []
for i in range(W):
    if np.sum(amat1[:,i]) != 0:
        mask2.append(i)
amat2 = amat1[:,mask2]

ans = []
for i in range(amat2.shape[0]):
    temp = ''
    for s in amat2[i]:
        if s == 1:
            temp += '#'
        else:
            temp += '.'
    ans.append(temp)
print(*ans, sep='\n')

Submission status: Accepted

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

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

for j in range(H):
    temp=0
    for k in range(W):
        if sq[j][k]==".":
            temp+=1
    if temp==W:
        delh.append(j)

for l in range(W):
    temp=0
    for m in range(H):
        if sq[m][l]==".":
            temp+=1
    if temp==H:
        delw.append(l)

for n in range(len(delh)):
    del sq[delh[n]]
    for q in range(len(delh)):
        delh[q]-=1
H-=len(delh)

for o in range(len(delw)):
    for p in range(H):
        del sq[p][delw[o]]
    for r in range(len(delw)):
        delw[r]-=1
        
for s in range(H):
    print("".join(sq[s]))

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
alist=['']*h
for i in range(h):
  alist[i]=input()
hlist=[]
wlist=[]
for i in range(h):
  flag=False
  for j in range(w):
    if alist[i][j]=='#':
      flag=True
  if flag:
    hlist.append(i)
for i in range(w):
  flag=False
  for j in range(h):
    if alist[j][i]=='#':
      flag=True
  if flag:
    wlist.append(i)
for i in hlist:
  ans=[]
  for j in wlist:
    ans.append(alist[i][j])
  print(''.join(ans))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]
b=[]
for i in range(H):
    if '#' in a[i]:
        b.append(a[i])
c=[[] for _ in range(len(b))]
for j in range(W):
    flag=False
    for i in range(len(b)):
        if b[i][j]=='#':
            flag=True
    if flag:
        for i in range(len(b)):
            c[i].append(b[i][j])
for i in range(len(c)):
    for j in range(len(c[i])):
        print(c[i][j],end='')
    print()

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    l = []
    for i in range(h):
        a = input()
        if "#" in a:
            l.append(a)
    l = [list(i) for i in zip(*l)]
    ans = []

    for i in l:
        if "#" in i:
            ans.append(i)

    ans = [i for i in zip(*ans)]
    for i in ans:
        print("".join(i))





if __name__=="__main__":
    main()

Submission status: Accepted

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

for i in range(h):
    r = list(input())
    if '#' in r:
        a.append(r)

box = [0] * w

for colum in range(w):
    if all(row[colum] == '.' for row in a) :
        box[colum] = 1

for j in range(w):
    if box[j] == 1:
        for row in a:
            row[j] = ''

for row in a:
    print(''.join(map(str, row)))

Submission status: Accepted

Solution code:
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
a = np.array([list(input()) for c in range(H)])
b = copy.deepcopy(a)
Hc=[]
Wc=[]
for i in range(H):
    if np.count_nonzero(a[i,:] == ".") == W:
        Hc.append(i)

for i in range(W):
    if np.count_nonzero(a[:,i] == ".") == H:
        Wc.append(i)

a = np.delete(a,Hc,0)
a = np.delete(a,Wc,1)

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

Submission status: Accepted

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

g = []
same = ['.'] * w
for _ in range(h):
    a = list(input())
    if a == same:
        continue
    else:
        g.append(a)

l = []
for j in range(w):
    for row in g:
        if row[j] == '#':
            break
    else:
        l.append(j)

for i in range(len(g)):
    g[i] = [g[i][j] for j in range(w) if j not in l]

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

Submission status: Accepted

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

y = []
for i in range(H):
    if set(x[i]) != {"."}:
        y.append(x[i])

z = np.array(y)
zz = np.rot90(z)
zzz = zz.tolist()

ans = []
for i in range(W):
    if set(zzz[i]) != {"."}:
        ans.append(zzz[i])

a = np.array(ans)
b = np.rot90(a, -1)
c = b.tolist()

for i in range(len(c)):
    print(*c[i], sep='')

Submission status: Accepted

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

cc =  [b for b in bb if any(x == '#' for x in b)]
dd =list(zip(*cc))
ee = [d for d in dd if any(x == '#' for x in d)]


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

Submission status: Accepted

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

d = [i for i in range(W)]

for i in range(W):
    f = 0
    for j in a:
        if j[i] == "#":
            f = 1
            break
    if f == 0:
        d.remove(i)

ans = [""] * H
for i in range(len(a)):
    for j in d:
        ans[i] += a[i][j]
    print(ans[i])

Submission status: Accepted

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

B = []
for i in range(H):
    if "#" in A[i]:
        B.append(A[i])

ans = []
for j in range(W):
    for i in range(len(B)):
        if "#" ==  B[i][j]:
            ans.append(j)
            break

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

Submission status: Accepted

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

for h in range(H):
    judge = False
    for w in range(W):
        if a[h][w] == "#":
            judge = True
    resH[h] = judge

for w in range(W):
    judge = False
    for h in range(H):
        if a[h][w] == "#":
            judge = True
    resW[w] = judge

for h, row in enumerate(a):
    tmp = []
    for w, element in enumerate(row):
        if resH[h] and resW[w]:
            tmp.append(element)
    if tmp:
        print(*tmp, sep="")

Submission status: Accepted

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

B = []
for row in A:
    if all(a=='.' for a in row): continue
    B.append(row)

C = ['' for _ in range(len(B))]
for col in zip(*B):
    if all(a=='.' for a in col): continue
    for i,a in enumerate(col):
        C[i] += a
for row in C:
    print(row)

Submission status: Accepted

Solution code:
H,W=list(map(int, input().split()))
A=[list(input()) for _ in range(H)]
S={i for i in range(H)}
T={j for j in range(W)}
for i in range(H):
  if set(A[i])=={'.'}:
    S-={i}
for j in range(W):
  for i in range(H):
    if A[i][j]=='#':
      break
  else:
    T-={j}
S=sorted(list(S))
T=sorted(list(T))
for i in S:
  ans=[]
  for j in T:
    ans.append(A[i][j])
  print(''.join(ans))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a = ['']*H
for i in range(H):
  a[i] = input()

h_flag = [0]*H
w_flag = [0]*W
for iHeight in range(H):
  for jWidth in range(W):
    if a[iHeight][jWidth] == '#':
      h_flag[iHeight] = 1
      w_flag[jWidth] = 1

for iHeight in range(H):
  if h_flag[iHeight] == 1:
    for jWidth in range(W):
      if w_flag[jWidth] == 1:
        print(a[iHeight][jWidth], end='')
    print()

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

H,W = mint()
A = [input() for _ in range(H)]
I = []
J = []

for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            I.append(i)
            break

for j in range(W):
    for i in range(H):
        if A[i][j]=='#':
            J.append(j)
            break

            
S = [[0]*len(J) for _ in range(len(I))]

for i in range(len(I)):
    for j in range(len(J)):
        print(A[I[i]][J[j]],end='')
    print('')

Submission status: Accepted

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

fin=[]
num=[0]*w

for l in lis:
  if l.count(".") != w:
    fin.append(l)
  for i in range(w):
    if l[i]==".":
      num[i]+=1

for f in fin:
  ans=[]
  for i in range(len(num)):
    if num[i]!=h:
      ans.append(f[i])
  print(*ans,sep='')

Submission status: Accepted

Solution code:
import sys
h,w = map(int,input().split())
square = [input() for i in range(h)]
y = "." * w
ans = []
index = []
for s in square:
  if s != y:
    ans.append(s)
h = len(ans)
for i in range(w):
  dot = 0
  for a in ans:
    if a[i] == ".":
      dot += 1
  if dot == h:
    index.append(i)

if len(index) == 0:
  for a in ans:
    print(a)
else:
  for a in ans:
    f = []
    for i,l in enumerate(a):
      if i not in index:
        f.append(l)
    print("".join(f))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
data=[0]*w
for i in range(h):
  a_=input()
  if a_!='.'*w:
    a.append(a_)
    for j in range(w):
      if a_[j]=='.':
        data[j]+=1
n=len(a)
for i in range(n):
  ans=[]
  for j in range(w):
    if data[j]!=n:
      ans.append(a[i][j])
  print(*ans,sep='')

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
# 列について
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            break
    # すべて空白だったらx印
    else:
        for l in range(W):
            A[i][l] = "x"

# 行について
for i in range(W):
    for j in range(H):
        if A[j][i] == "#":
            break
    else:
        for l in range(H):
            A[l][i] = "x"
for i in range(H):
    x_cnt = 0
    for j in range(W):
        if A[i][j] != "x":
            print(A[i][j], end="")
        else:
            x_cnt += 1

    if x_cnt < W:
        print()
    else:
        pass

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
masu = [list(input())for i in range(H)]
excludeC = []
excludeR = []
for i in range(H):
    if masu[i].count('.') == W:
        excludeR.append(i)

for i in range(W):
    isExclude = True
    for j in range(H):
      if masu[j][i] == '#':
            isExclude = False
            break
    if isExclude:
        excludeC.append(i)

for i in range(H):
    if i in excludeR:
        continue
    for j in range(W):
        if j in excludeC:
            continue
        print(masu[i][j],end='')
    print('')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = list()
y = list()
for i in range(h):
    if "#" in a[i]:
        x.append(i)
for j in range(w):
    cnt = 0
    for k in range(h):
        if a[k][j] == "#":
            y.append(j)
            break
for p in x:
    z = ""
    for q in y:
        z += a[p][q]
    print(z)

Submission status: Accepted

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

h_set = set()
w_set = set()
B = [input() for i in range(H)]
for i in range(H):
  for j in range(W):
    if B[i][j] == '#':
      w_set.add(j)
      h_set.add(i)
      
for i in range(H):
  if i in h_set:
    t = ""
    for j in range(W):
      if j in w_set:
        t += B[i][j]
    print(t)

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [str(input()) for _ in range(h)]
b = []
for i in range(h):
    if a[i] != '.'*w:
        b.append(a[i])
c = []
for h in range(w):
    num = 0
    for j in b:
        if j[h] == '.':
            num += 1
    if num == len(b):
        c.append(h)
for k in b:
    word = ""
    for l in range(w):
        if l not in c:
            word += k[l]
    print(word)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    H, W = map(int, input().split())
    a = []
    white = '.' * W
    for i in range(H):
        s = input()
        if s == white:
            pass
        else:
            a.append(s)

    black = []
    for w in range(W):
        for h in range(len(a)):
            if a[h][w] == '#':
                black.append(w)

    black = sorted(list(set(black)))
    for h in range(len(a)):
        t = ''
        for b in black:
            t += a[h][b]
        print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

H = len(A)
if H == 1:
    A = list(itertools.chain.from_iterable(A))
    cnt = []
    for ans in A:
        if ans == "#":
            cnt.append(ans)
    print("".join(cnt))
else:
    L = []
    for w in range(W):
        l = []
        for h in range(H):
            if A[h][w] == "#":
                l = []
                break
            l.append(w)
        if len(l) != 0:
            L.append(l[0])

    dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
    for ans in A:
        ans = dellist(ans, L)
        print("".join(ans))

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H, W = map(int, input().split())

ignore = "".join(["." for _ in range(W)])

A = list(filter(lambda x : x != ignore, [input() for _ in range(H)]))
H = len(A)
B = [[] for _ in range(H)]

for w in range(W):
    if list(filter(lambda x: x[w] == "#", A)):
        for i in range(H):
            B[i].append(A[i][w])

for h in range(H):
    print("".join(B[h]))

Submission status: Accepted

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

for i in range(h):
    if a[i].count('.') == w:
        sdel.append(i)

for i in range(w):
    cnt = 0
    for j in range(h):
        if a[j][i] == '.':
            cnt += 1
    if cnt == h:
        vdel.append(i)
i = 0
lens = len(sdel)-1
h -= lens+1
while i <= lens:
    del a[sdel[lens]]
    lens -= 1

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = [input() for i 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:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)

a2=[]
a3=[]
for i in range(h):
  if "#" in a[i]:
    a2.append(a[i])
a2=np.array(a2)
a2=a2.T

for i in range(len(a2)):
  if "#" in a2[i]:
    a3.append(a2[i])
a3=np.array(a3)
a3=a3.T
for i in range(len(a3)):
  print("".join(a3[i]))

Submission status: Accepted

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

def check_row(grid):
    for i in range(len(grid)):
        if "#" not in grid[i]:
            return i
    return -1

def check_col(grid):
    grid_inv = []
    for i in range(len(grid[0])):
        grid_inv.append("".join(row[i] for row in grid))
    return check_row(grid_inv)

while True:
    if check_row(grid) != -1:
        del grid[check_row(grid)]
        continue
    elif check_col(grid) != -1:
        d = check_col(grid)
        for i in range(len(grid)):
            grid[i] = grid[i][:d] + grid[i][d+1:]
    else:
        break

for g in grid:
    print(g)

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 j in range(H):
  for k in range(W):
    if A[j][k] == "#":
      row[j] = True
      col[k] = True
      
for l in range(H):
  if row[l]:
    for m in range(W):
      if col[m]:
        print(A[l][m], end = "")
    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
A = [input() for i 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 = [i for i in [input() for i in range(h)] if "#" in i]
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)]
i = 0
for a in range(H):
    if '#' not in A[i]:
        del A[i]
        H -= 1
        i -= 1
    i += 1
#ここまでで行消去
i = 0
for a in range(W):
    f = True
    for j in range(H):
        if A[j][i] == '#':
            f = False
            break
    if f:
        for j in range(H):
            A[j] = A[j][:i] + A[j][i+1:]
        W -= 1
        i -= 1
    i += 1
for a in A:
    print(a)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
ans=[i for i in a if '#' in i]
s=[]
for i in range(w):
	t=0
	for j in a:
		t+=(j[i]=='#')
	if t==0:
		s+=[i]
for i in s[::-1]:
	for j in ans:
		del j[i]
for i in ans:
	print(''.join(i))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc107/tasks/abc107_b
h, w = [int(i) for i in input().split()]
grid = []

for _ in range(h):
    line = list(input())
    if "#" in line:
        grid.append(line)

ans = [[] for _ in range(len(grid))]

for i in range(w):
    for j in range(len(grid)):
        if grid[j][i] == "#":
            break
    else:
        continue
    for k in range(len(grid)):
        ans[k].append(grid[k][i])

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

Submission status: Accepted

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

for i in range(H):
    if '#' not in grid[i][0]:
        check.append(i-len(check))
for i in check:
    grid = grid[:i] + grid[i+1:]
check = []

for i in range(W):
    if all(grid[j][0][i]=='.' for j in range(len(grid))):
        check.append(i - len(check))
for i in check:
    for k in range(len(grid)):
        grid[k][0] = grid[k][0][:i] + grid[k][0][i+1:]
        
for i in grid:
    print(i[0])

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    H,W =map(int,input().split())
    A =[]
    h = []
    w = []
    count =0
    for i in range(H):
        a = list(str(input()))
        if a.count('#')==0:
            continue
        else:
            A.append(a)
            count +=1


    for j in range(W):
        for i in range(count):
            if A[i][j] =="#":
                break

            if i == count-1:
                w.append(j)

    for i in range(count):
        for j in range(W):
            if j not in w:
                print(A[i][j],sep="",end="")
        print("")







if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
G=[list(input()) for i in range(H)]
allwhite=['.']*W
tmp=[]
for i in range(H):
    if G[i]!=allwhite:
        tmp.append(G[i])
G=tmp
ans=["" for i in range(len(G))]
for j in range(W):
    p=False
    for i in range(len(G)):
        if G[i][j]=='#':
            p=True
            break
    if p:
        for i in range(len(G)):
            ans[i]+=G[i][j]
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
ans = []
for i in range(H):
    a = input()
    if a != "."*W:
        ans.append(a)
H = len(ans)
ans2 = list(map(list,zip(*ans)))
while ["."]*H in ans2:
    ans2.remove(["."]*H)
trueans = list(map(list,zip(*ans2)))
for i in trueans:
    print("".join(i))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w =  map(int,input().split())
mat = [input() for i in range(h)]
n = 0
max = h
while n<max:
    if mat[n]=="."*w:
        mat.pop(n)
        n -= 1
        max -= 1
    n += 1
flag = [True for i in range(w)]
for i in mat:
    for j in range(w):
        if i[j]=="#":
            flag[j] = False
ans = []
for i in mat:
    temp = ""
    for j in range(w):
        if not flag[j]:
            temp += i[j]
    ans.append(temp)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for _ in range(H):
    a = input()
    if "#" in a:
        A.append(a)
A_ = ["" for _ in range(len(A))]
for x in range(W):
    f = False
    for a in A:
        if a[x] == "#":
            f = True
            break
    if f:
        for y, a in enumerate(A):
            A_[y] += a[x]
for a in A_:
    print(a)

Submission status: Accepted

Solution code:
#12 B - Grid Compression
H,W = map(int,input().split())
a = [list(input()) for _ in range(H)]

i = 0
while i < len(a):
    if all(m == '.' for m in a[i]) :
        a.pop(i)
    else:
        i += 1
#加工したaにおけるHを保持しなおす
H_sc = len(a)
w = 0
while w < len(a[0]):
    cnt = 0
    for h in range(H_sc):
        if a[h][w] == '#':
            w += 1
            break
        else:
            cnt += 1
    if cnt == H_sc:
        for b in a:
            b.pop(w)
for g in a:
    print(''.join(g))

Submission status: Accepted

Solution code:
a = input().split()
H = int(a[0])
W = int(a[1])
adj = int(0)
s = []
p = []

for k in range(H):
    m = input()
    for i in range(W):
        p.append(m[i])
    s.append(p)
    p = []

for i in range(W):
    i = i - adj
    temp = int(0)
    for k in range(H):
        if s[k][i] == "#":
            temp = 1
            break
        else:
            pass
    if temp == 0:
        for k in range(H):
            del s[k][i]
        adj += 1
    else:
        pass

W = W - adj
adj = 0

for i in range(H):
    i = i - adj
    temp = int(0)
    for k in range(W):
        if s[i][k] == "#":
            temp = 1
            break
        else:
            pass
    if temp == 0:
        del s[i]
        adj += 1
    else:
        pass

H = H - adj

for i in range(H):
    tinpo = ''.join(s[i])
    print(tinpo)

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a0 = [[] for i in range(h)]
for i in range(h):
  a0[i] = input()
a = [j for j in a0 if "#" in j]
at0 = list(map(list, zip(*a)))
for k in range(len(at0)):
  at0[k] = "".join(at0[k])
at = [l for l in at0 if "#" in l]
for m in list(map(list, zip(*at))):
  print("".join(m))

Submission status: Accepted

Solution code:
import numpy as np

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

gyo = np.all(hw == ".",axis=1)
retu= np.all(hw == ".",axis=0)

for i in range(H):
    if not gyo[i]==True:
        for j in range(W):
            if not retu[j]==True:
                print(hw[i][j],end="")
        print()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


H, W = zz()
board = []
for h in range(H):
    board.append(list(input()))
board = np.array(board)
ans1 = []
for h in range(H):
    if ('#' in board[h]):
        ans1.append(board[h])
ans2 = []
board = np.array(ans1)
for w in range(W):
    if ('#' in board[:, w]):
        ans2.append(board[:, w])
ans2 = np.array(ans2).T

for line in ans2:
    print(*line, sep='')

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    h,w = LI()
    board = []
    for _ in range(h):
        line = list(S())
        board.append(line)
    
    wpro = []
    wline = ["." for _ in range(w)]

    for line in board:
        if line != wline:
            wpro.append(line)
    
    hpro = list(zip(*wpro))
    hline = tuple(["." for _ in range(len(hpro[0]))])
    # print(hline)
    ans = []
    # print(hpro)
    for line in hpro:
        if line!= hline:
            ans.append(line)
    
    ans = list(zip(*ans))
    for line in ans:
        print("".join(line))
main()

Submission status: Accepted

Solution code:
import numpy as np

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

gyo = np.all(hw == ".",axis=1)
retu= np.all(hw == ".",axis=0)

for i in range(H):
	if not gyo[i]==True:
		for j in range(W):
			if not retu[j]==True:
				print(hw[i][j],end="")
		print()

Submission status: Accepted

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

res =[]

for i in range(h):
    if ab[i].count(".") ==w:
        pass
    else:
        res.append(ab[i])

l = len(res)

ress=[]
for j in range(w):
    b = list(map(lambda x: x[j], res))
    if b.count(".") ==l:
        pass
    else:
        ress.append(b)

ans = list(zip(*ress))

for i in range(l):
    print(''.join(ans[i]))

Submission status: Accepted

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

#行
r = [0]*H  #行ごとの#の数
for i in range(H):
    r[i]=a[i].count('#')
#列
c = [0]*W  #列ごとの#の数
for i in a:
    for j in range(W):
        if i[j]=='#':
            c[j]+=1
            
for i in range(H):
    a[i] = [a[i][j] for j in range(W) if c[j]!=0]


for i in range(H):
    if r[i]!=0:
        print(''.join(a[i]))

Submission status: Accepted

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

a=[list(map(str,input().split())) for i in range(H)]
for i in range(H):
    a[i]=list(a[i][0])
flag=True
for i in range(H):
    for j in range(W):
        if a[H-1-i][j]!='.':
            flag=False
            break
    if flag:
        del(a[H-1-i])
    flag=True
for i in range(W):
    for j in range(len(a)):
        if a[j][W-1-i]!='.':
            flag=False
            break
    if flag:
        for j in range(len(a)):
            del(a[j][W-1-i])
    flag=True

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