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())

temp = [list(map(int,input().replace("#", "1").replace(".","0"))) for _ in range(H)]

cnt = 0


while cnt != 2:
    ans = []
    s = 0
    for row in temp:
        if sum(row) != 0:
            ans.append(row)
        else:
            s += 1
    if s == 0:
        cnt += 1
    else:
        cnt = 0
        
            
    temp = []
    for row in zip(*ans):
        temp.append(row)
    
    ans = []
    s = 0
    for row in temp:
        if sum(row) != 0:
            ans.append(row)
        else:
            s += 1
    if s == 0:
        cnt += 1
    else:
        cnt = 0
            
    temp = []
    for row in zip(*ans):
        temp.append(row)


for row in temp:
    res = list(map(str,row))
    res = ",".join(res).replace("1","#").replace("0",".").split(",")
    print("".join(res))

Submission status: Accepted

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

A = [list(input()) for _  in range(H)]
h = set()
w = set()

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            h.add(i)
            w.add(j)

for i in h:
    for j in w:
        print(A[i][j], end="")
    print()

Submission status: Accepted

Solution code:
def transpose(A):
    B = []
    for j in range(len(A[0])):
        C = [A[i][j] for i in range(len(A))]
        B.append(C)
    return B

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

for i in reversed(range(H)):
    if A[i] == ['.']*W:
        A.pop(i)
        
H = len(A)        
A = transpose(A)
for j in reversed(range(W)):
    if A[j] == ['.']*H:
        A.pop(j)

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
k=[]
for _ in range(h):
  s=input()
  if '#' in s:
    a.append(s)
l=len(a)
for i in range(w):
  for j in range(l):
    if a[j][i]=='#':
      k.append(i)
      break
m=max(k)
for i in range(l):
  for j in k:
    if j==m:
      print(a[i][j])
    else:
      print(a[i][j],end="")

Submission status: Accepted

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

aT = list(zip(*a))
aT = [x for x in aT if '#' in x]
ans = list(zip(*aT))

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

Submission status: Accepted

Solution code:
def abc():
    h, w = map(int, input().split())
    lines = []
    for i in range(h):
        line = list(input().rstrip())
        if '#' in line:
            lines.append(line)

    for x in reversed(range(w)):
        if len([l for l in lines if l[x] == '#']) == 0:
            for l in lines:
                l.pop(x)
    for line in lines:
        print(''.join(line))


abc()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
del_list = []
n = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            break
    else:
        del_list.append(i)
for i in reversed(del_list):
    del a[i]
del_list = []
for j in range(len(a[0])):
    for i in range(len(a)):
        if a[i][j] == "#":
            break
    else:
        del_list.append(j)
for j in reversed(del_list):
    for i in range(len(a)):
        del a[i][j]
for i in range(len(a)):
    ans = ""
    for j in range(len(a[0])):
        ans += a[i][j]
    print(ans)

Submission status: Accepted

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

# PROCESS

# 列をチェックして削除
def delete_row(mp):
  new_mp = []
  for row in mp:
    if ("#" in row):
      new_mp.append(row)
  return len(new_mp) < len(mp), new_mp

# 行をチェックして削除
def delete_column(mp):
  new_mp = []

  # 削除
  allow_columns = [0 for _ in range(len(mp[0]))]
  for row in mp:
    for cell_idx in range(len(row)):
      if (row[cell_idx] == "#"):
        allow_columns[cell_idx] = 1

  for row in mp:
    allow_row = []
    for cell_idx in range(len(row)):
      if (allow_columns[cell_idx] == 1):
        allow_row.append(row[cell_idx])
    new_mp.append(allow_row)

  return 0 in allow_columns, new_mp

deleted = True
while(deleted):
  deleted, mapping = delete_row(mapping)
  deleted, mapping = delete_column(mapping)

answer = mapping

# OUTPUT
for row in answer:
  print("".join(row))

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
s=[list(input()) for i in range(h)] 
x=0
v=0
count=0
for i in range(h):
    if s[x].count('.')==w:
        del s[x] 
    else:
        x+=1
for j in range(w):
    for i in range(len(s)):
        if s[i][v]=='.':
            count+=1
    if count==len(s):
        count=0
        for i in range(len(s)):
            del s[i][v]
    else:
        v+=1
        count=0
        
for i in range(len(s)):
    print(''.join(s[i]))

Submission status: Accepted

Solution code:

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

a = []

for i in range(H):

    newa = input()
    newa_l = list(newa)
    a.append(newa_l)

bigbul = True
while bigbul:

    bigbul = False
    acp = a.copy()
    
    for i in range(H):
    
        bul = True
        for j in range(W):

            if a[i][j] != ".":
                bul = False
                break

        if bul:
            del acp[i]
            a = acp.copy()
            H -= 1
            bigbul = True
            break

bigbul = True
while bigbul:

    bigbul = False
    acp = a.copy()

    #print("W", W)

    for j in range(W):

        bul = True

        for i in range(H):

            if a[i][j] != ".":
                bul = False
                break


        if bul:

            for k in acp:

                del k[j]
                #print ("nowk")

                #for i in acp:
                    #ans = "".join(i)
                    #print (ans)

            a = acp.copy()
            W -= 1
            bigbul = True
            break

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

Submission status: Accepted

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

flag_row = [True] * H
flag_col = [True] * W

for i in range(H):
    cnt = 0
    for j in range(W):
        if a[i][j] == '.':
            cnt += 1
    if cnt == W:
        flag_row[i] = False

for j in range(W):
    cnt = 0
    for i in range(H):
        if a[i][j] == '.':
            cnt += 1
    if cnt == H:
        flag_col[j] = False

for i in range(H):
    for j in range(W):
        if flag_row[i] == True and flag_col[j] == True:
            print(a[i][j], end='')
    if flag_row[i] == True:
        print()

Submission status: Accepted

Solution code:
import numpy as np
import sys

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

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

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

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

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

Submission status: Accepted

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

res=[]
for i in range(h):
	a=list(input())
	if a.count('.')==w:continue
	res+=list([a]) 
col=[True]*w
for i in range(len(res)):
	for j in range(w):
		if res[i][j]=='#':col[j]=False
		
for i in range(len(res)):
	for j in range(w):
		if col[j]==False:print(res[i][j],end='')
	print()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  h,w=LI()
  a=[]
  for _ in range(h):
    a.append(S())

  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()

main()

Submission status: Accepted

Solution code:
import numpy as np

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

A = np.zeros((H, W), dtype=np.int)

for i in range(H):
    s = input()
    c = [j for j in range(W) if s[j] == "#"]
    A[i][c] = 1

while True:
    # find x
    a = A.sum(axis=0)
    if np.any(a == 0):
        del_lines = np.where(a == 0)[0]
        A = np.delete(A, del_lines, axis=1)
        continue

    # find y
    a = A.sum(axis=1)
    if np.any(a == 0):
        del_lines = np.where(a == 0)[0]
        A = np.delete(A, del_lines, axis=0)
        continue

    # break if no white line
    break

A = A.tolist()
num2char = {0: ".", 1: "#"}
for l in A:
    s = list(map(lambda x: num2char[x], l))
    print("".join(s))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
  aa=list(input())
  if "#" not in aa:
    continue
  else:
    a.append(aa)
aa=[]
for i in range(w):
  c=0
  for j in range(len(a)):
    if a[j][i]=="#":
      c+=1
  if c==0:
    aa.append(i)
aa.reverse()
for i in aa:
  for j in range(len(a)):
    del a[j][i]
for i in range(len(a)):
  print("".join(a[i]))

Submission status: Accepted

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

i = w-1
while i >= 0:
    col = ""
    for j in range(h):
        col += f[j][i]
    if col == "."*h:
        for j in range(h):
            del f[j][i]
    i -= 1

i = h-1
while i >= 0:
    if set(f[i]) == {"."}: del f[i];
    i -= 1

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

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

H, W = list(map(int, sys.stdin.readline().split()))
A = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)])

cols = np.array([c for c in A.T if np.any(c == '#')])
rows = np.array([r for r in cols.T if np.any(r == '#')])

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

Submission status: Accepted

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

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

for j in range(W):
    cnt = 0
    for i in range(H):
        if a[i][j] == '.':
            cnt += 1
    if cnt == H:
        w.append(j)

for i in range(H):
    if i in h:
        continue
    for j in range(W):
        if j in w:
            continue
        print(a[i][j],end='')
    print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
st=set()
list=list()
for i in range(H):
    S=input()
    if S.count('.') != W:
        list.append(S)
    tmp=S
    tmp=[int(i) for i,x in enumerate(tmp) if x == '.']
    if not st:
        tmp_set = set(tmp)
        st=st.union(tmp_set)
    else:
        tmp_set = set(tmp)
        st &=tmp_set
for x in list:
    str=''
    if not st:
        for i in range(W):
            str+=x[i]
    else:
        for i in range(W):
            if i not in st:
                str+=x[i]
    print(str)
    str=''

Submission status: Accepted

Solution code:
import itertools

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

grid = filter(lambda r: any(map(lambda c : c == '#', r)), grid)
grid = zip(*grid)
grid = filter(lambda r: any(map(lambda c : c == '#', r)), grid)
grid = zip(*grid)

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

Submission status: Accepted

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

whiteh = []
whitew = []
for i in range(h):
  if grid[i] == "."*w:
    whiteh.append(i)

for i in reversed(whiteh):
  grid.pop(i)
h -= len(whiteh)

grid2 = [""]*w
for i in range(h):
  for j in range(w):
    grid2[j] += grid[i][j]    
    
for i in range(w):
  if grid2[i] == "."*h:
    whitew.append(i)    
    
for i in reversed(whitew):
  grid2.pop(i)
w -= len(whitew)

gridans = [""]*h
for i in range(w):
  for j in range(h):
    gridans[j] += grid2[i][j] 

for i in range(h):
  print(gridans[i])

Submission status: Accepted

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

allwhiteh = [1] * H
allwhitev = [1] * W
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            allwhiteh[i] = 0
            allwhitev[j] = 0

for i in range(H):
    for j in range(W):
        if not allwhiteh[i] and not allwhitev[j]:
            print(a[i][j], end="")
    if not allwhiteh[i]:
        print("")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = list(zip(*[j for j in list(zip(*[i for i in [list(input()) for _ in range(H)] if "#" in i])) if "#" in j]))
for n in range(len(a)):
	print("".join(a[n]))

Submission status: Accepted

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

a = list(zip(*[i for i in a if "#" in i]))
a = list(zip(*[j for j in a if "#" in j]))
for n in range(len(a)):
	print("".join(a[n]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
a = [i for i in a if "#" in "".join(i)]
# print("step1", a)
a = list(zip(*a))
# print("step2", a)
a = [j for j in a if "#" in "".join(j)]
# print("step3", a)
a = list(zip(*a))
# print("step4", a)
for n in range(len(a)):
	print("".join(a[n]))

Submission status: Accepted

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

b = []
def solve(ls,i,j,h,w):
	flg = 0
	for k in range(w):
		if ls[i][k] == "#":
			flg += 1
			break
	for l in range(h):
		if ls[l][j] == "#":
			flg += 1
			break
			
	if flg ==2:
		return True
	else:
		return False

			

for i in range(h):
	c = []
	for j in range(w):
		if a[i][j] == "#":
			c.append("#")
		elif solve(a,i,j,h,w):
			c.append(".")
		else:
			pass
	b.append(c)

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
hw=[input() for i in range(h)]
thw=[]
for i in range(h):
    if hw[i].count('#')!=0:
        thw+=[hw[i]]
ans=['']*len(thw)
for i in range(w):
    flg=False
    for j in range(len(thw)):
        if thw[j][i]=='#':
            flg=True
            break
    if flg:
        for j in range(len(thw)):
            ans[j]+=thw[j][i]
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
Hli,Wli = [0 for _ in range(h)],[0 for _ in range(w)]
A = []
for i in range(h):
    l = input()
    for j in range(w):
        if l[j] == "#":
            Hli[i] = 1
            Wli[j] = 1
    A.append(l)
# print(Hli,Wli)
for i in range(h):
    str = ""
    for j in range(w):
        if Hli[i]*Wli[j] == 1:
            str += A[i][j]
    if str != "": print(str)

Submission status: Accepted

Solution code:
h,w= map(int, input().split())
s = []
a = []
for i in range(h):
    temp = input()
    if '#' in temp:
        s.append(temp)
for j in range(w):
    flag = False
    for i in s:
        if i[j] == '#':
            flag = True
            break
    a.append(flag)
s = ["".join(j[i] for i in range(w) if a[i]) for j in s]
 
for x in s:
    print(x)

Submission status: Accepted

Solution code:
import math
 
h,w = list(map(int, input().split()))
data = []
for i in range(h):
    a=list(map(str, input().split()))
    data.append(a[0])

hlist=[]
wlist=[]
for i in range(h):
    flag=0
    for j in range(w):
        if(data[i][j]=='#'):
            flag=1
    if(flag==1):
        hlist.append(i)

for i in range(w):
    flag=0
    for j in range(h):
        if(data[j][i]=='#'):
            flag=1
    if(flag==1):
        wlist.append(i)
        

for i in range(len(hlist)):
    temp=""
    for j in range(len(wlist)):
        temp+=data[hlist[i]][wlist[j]]
    print(temp)

Submission status: Accepted

Solution code:
H, W = [int(hw) for hw in input().split()]
A = []
for h in range(H):
  a = [a for a in input()]
  if a.count("#") > 0:
    A.append(a)

for w in reversed(range(W)):
  cnt = 0
  for h in range(len(A)):
    if A[h][w] == ".":
      cnt += 1
  if cnt == len(A):
    for h in range(len(A)):
      del A[h][w]

for h in range(len(A)):
  ans = "".join(A[h])
  print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ret = []
for r in grid:
    if any(x == '#' for x in r):
        ret.append(r)
grid = np.array(ret).T.tolist()

ret = []
for r in grid:
    if any(x == '#' for x in r):
        ret.append(r)

grid = np.array(ret).T.tolist()

for r in grid:
    print(*r, sep='')

Submission status: Accepted

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

Hcnt = [0] * H
Wcnt = [0] * W

L = [list(input()) for _ in range(H)]

for i, s in enumerate(L):
  for j, c in enumerate(s):
    if c == "#":
      Hcnt[i] += 1
      Wcnt[j] += 1

for i, s in enumerate(L):
  if Hcnt[i] <= 0:
    continue
  for j, c in enumerate(s):
    if Wcnt[j] > 0:
      print(c, end="")
  print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for i in range(H)]
 
a = ["".join(row) for row in zip(*a) if row.count("#") > 0]
a=  ["".join(row) for row in zip(*a) if row.count("#") > 0]
 
print("\n".join(a))

Submission status: Accepted

Solution code:
h, w =  [ int(v) for v in input().split() ]
column_list = []
row_list = []
field = [ None for i in range(h) ]
space_column = "." * w
space_row = "." * h
for i in range(h):
	s = input()
	field[i] = s
	if s != space_column:
		column_list.append(i)

for i in range(w):
	s = "".join([field[j][i] for j in range(h)])
	if s != space_row:
		row_list.append(i)


for i in column_list:
	print("".join([ field[i][j] for j in row_list ]))

Submission status: Accepted

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

grid = []

for _ in range(h):
    line = input().rstrip()
    if line.count('#') == 0:
        continue
    grid.append(line)


remove_columns = []

for c in range(w):
    for r in range(len(grid)):
        if grid[r][c] == '#':
            break
    else:
        remove_columns.append(c)

for line in grid:
    for i, l in enumerate(line):
        if i not in remove_columns:
            print(l, end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[]
for i in range(H):
  a=input()
  A.append(a)
aw_h=[]
aw_v=[]
for i in range(H):
  if '#' not in A[i]:
    aw_h.append(i)
for i in range(len(aw_h)):
  A.pop(aw_h[i]-i)
for i in range(W):
  count=0
  for j in range(len(A)):
    if A[j][i]=='.':
      count+=1
  if count==len(A):
    aw_v.append(i)
for i in range(len(A)):
  for j in range(len(aw_v)):
    A[i]=A[i][:aw_v[j]-j]+A[i][aw_v[j]-j+1:]
for i in range(len(A)):
  print(str(A[i]))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=[]
for i in range(a):
  g=input()
  if "#" not in g:
    continue
  d=list(g)
  c.append(d)
l=len(c)
p=[]
for i in range(b):
  for j in range(l):
    if c[j][i]=="#":
      p.append(i)
      break
for i in range(l):
  for j in range(len(p)):
    if j == len(p)-1:
      print(c[i][p[j]])
    else:
      print(c[i][p[j]],end="")

Submission status: Accepted

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

row = [0] * h
col = [0] * w

for i in range(h):
    if '#' in a[i]:
        row[i] = True

for i in range(h):
    for j in range(w):
        if '#' == a[i][j]:
            col[j] = True

for i in range(h):
    output = ''
    for j in range(w):
        if row[i] and col[j]:
            output += a[i][j]
    if not output == '':
        print(output)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
cnt = [0]*w
wRemove = 0
hRemove = 0
squares = []
hRemoveList = []
wRemoveList = []
for _ in range(h) :
        a = list(input())
        squares.append(a)
for i in range(h) :
        for j in range(w) :
                if squares[i][j] == '.' :
                        cnt[j] += 1
for i in range(w) :
        if cnt[i] == h :
                wRemove += 1
                wRemoveList.append(i)
wRemoveList.sort(reverse = True)
if not wRemoveList == [] :
        for i in range(h) :
                for j in wRemoveList :
                        del squares[i][j]
for i in range(h) :
        if squares[i] == ['.']*(w - wRemove) :
                hRemove += 1 
                hRemoveList.append(i)   
hRemoveList.sort(reverse = True)           
for i in hRemoveList :
        del squares[i]
for i in range(h-hRemove) :  
        print(''.join(squares[i]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[j for j in input()] for i in range(h)]
for i in range(h):
  if a[i].count('.')==w:
    a[i]=[]
while [] in a:
  a.remove([])
for i in range(w):
  c=0
  for j in range(len(a)):
    if a[j][i]=='.':
      c+=1
  if c==len(a):
    for j in range(len(a)):
      a[j][i]='!'
for i in range(len(a)):
  while '!' in a[i]:
    a[i].remove('!')
for i in a:
  print(*i,sep='')

Submission status: Accepted

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

if "#" in a:
    pages = [a]
else:
    pages = []

for i in range(h-1):
    a = input()
    if "#" in a:
        pages.append(a)
    else:
        continue
    for j in box:
        if a[j] != ".":
            box.remove(j)

box.reverse()
for i in range(len(pages)):
    for j in box:
        pages[i] = pages[i][:j] + pages[i][j+1:]

    print(pages[i])

Submission status: Accepted

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

while '.' * W in A:
    A.remove('.' * W)

remove_j = set()
for j in range(W):
    if set([A[i][j] for i in range(len(A))]) == {'.'}:
        remove_j.add(j)

active_j = set(range(W)) - remove_j
active_j = sorted(list(active_j))
for a in A:
    print(''.join([a[j] for j in active_j]))

Submission status: Accepted

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

c=[]
for li in a:
    if li!=['.']*len(li):
        c.append(li)

b=[]
for lc in zip(*c):
    if lc!=('.',)*len(lc):
        b.append(lc)

for ld in zip(*b):
    print(''.join(ld))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
for i in range(h):
    a.append(input())
hh = [False]*h
ww = [False]*w
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            hh[i]=True
            ww[j]=True
for i in range(h):
    if hh[i]:
        for j in range(w):
            if ww[j]:
                print(a[i][j],end="")
        print()

Submission status: Accepted

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

a = [""]*H

for i in range(H):
    a[i]=input()

row = [False]*H
col = [False]*W

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True

for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(a[i][j],end='')
        print()

Submission status: Accepted

Solution code:
# 入力
H,W=map(int,input().split())
 
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:
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
dl=[]
for i in range(h):
    if "#" not in l[i]:dl.append(i)
for i in dl[::-1]:
    del l[i]
l = [list(x) for x in zip(*l)]
dl=[]
for i in range(w):
    if "#" not in l[i]:dl.append(i)
for i in dl[::-1]:
    del l[i]
l = [list(x) for x in zip(*l)]
for i in l:print("".join(map(str,i)))

Submission status: Accepted

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

li = []

for i in range(h):
  wi = input()
  if wi.count('#') > 0:
    li.append(wi)

ans = [[0 for i in range(w)] for j in range(len(li))]
  
for i in range(w):
  line = []
  for j in range(len(li)):
    line.append(li[j][i])
  if line.count('#') != 0:
    for j in range(len(li)):
      ans[j][i] = line[j]

for i in ans:
  a = []
  for j in i:
    if j != 0:
      a.append(j)
  print(''.join(a))

Submission status: Accepted

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

row = [False] * H
col = [False] * W
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(a[i][j],end='')
        print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [''] * h
# 行の数だけ入力
for i in range(h):
  a[i] = input()

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

# 各セルについてTrue/Falseを設定
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=[]
A=[[i for i in input()] for _ 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())
l=[list(input()) for i in range(h)]
hs=set()
ws=set()
for i in range(h):
    for j in range(w):
        if l[i][j]=="#":
            hs.add(i)
            ws.add(j)
for i in hs:
    for j in ws:
        print(l[i][j],end="")
    print()

Submission status: Accepted

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

for _ in range(H):
    sd = list(input())
    if '#' in sd:
        a.append(sd)

col = [False] * W

for i in range(W):
    if '#' in [row[i] for row in a]:
        col[i] = True

for i in range(len(a)):
    for j in range(W):
        if col[j]:
            print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    h, w = f()
    lines = []
    for i in range(h):
        lines.append(input())
    
    rl = set()
    rc = set()
    for i in range(h):
        for j in range(w):
            if lines[i][j]== '#':
                rl.add(i)
                rc.add(j)
    
    rl = sorted(rl)
    rc = sorted(rc)

    for i in rl:
        for j in rc:
            print(lines[i][j], end = '')
        print()



solve()

Submission status: Accepted

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

for i in range(h):
    for x in range(w):
        if a[i][x] == '#':
            row[i] = True
            col[x] = True
for i in range(h):
    if row[i]:
        for x in range(w):
            if col[x]:
                print(a[i][x],end='')
        print()

Submission status: Accepted

Solution code:
H,W = list(map(int,input().split()))
b = []
if H == 1:
    print(input())
else:
    for _ in range(H):
        a = input()
        if a.count('.') == W:
            pass
        else:
            b.append(a)
    st = set()
    #print(b)
    for i,c in enumerate(b[0]):
        if c == '.':
            st.add(i)
    for a in b[1:]:
        s_st = set()
        for k in st:
            if a[k] == '#':
                s_st.add(k)
        st -= s_st
    #print(st)
    for c in b:
        for i,d in enumerate(c):
            if not i in st:print(d,end='')
        else:print('')

Submission status: Accepted

Solution code:
H, W = map(int, raw_input().split())
board = []
for i in range(0, H):
	s = raw_input()
	lst = []
	for j in range(0, W):
		lst.append(s[j])
	board.append(lst)
down = []
for i in range(0, W):
	down.append(False)
for i in range(0, H):
	for j in range(0, W):
		if board[i][j] == '#': down[j] = True
for i in range(0, H):
	if '#' in board[i]:
		outs = ''
		for j in range(0, W):
			if down[j]: outs = outs + board[i][j]
		print outs

Submission status: Accepted

Solution code:

import math
H,W = list(map(int,input().split(" ")))
mas = []
for _ in range(H):
    temp = input()
    if temp == "."*W :
        temp = "-" * W
    mas.append(list(temp))
for w in range(W):
    flag = True
    for h in range(H):
        if mas[h][w]  == "#":
            flag = False
            break
    if flag:
        for h in range(H):
            mas[h][w] = "-"

for h in range(H):
    flag = False
    for w in range(W):
         if mas[h][w] != "-":
            print(mas[h][w],end="")
            flag = True
    if flag:
        print()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import *

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H , W = map(int,input().split())

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

    AA = [not all(x=="." for x in a) for a in A]
    BA = [not all(x=="." for x in b) for b in B]

    for a in compress(A,AA):
        for b in compress(a,BA):
            print(b,end="")
        print("")

    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()