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:
import numpy as np
H, W = map(int, input().split())
a = []
for i in range(H):
  s = str(input())
  l = [c for c in s]
  a.append(l)
  
a = np.array(a)
cnt = 0
for i in range(H):
  s = np.array([a[0]])
  a = np.delete(a, 0, 0)
  if '#' in s:
    a = np.append(a, s, axis=0)
    cnt += 1
    
for i in range(W):
  s = np.array([a[:, 0]]).reshape(cnt, 1)
  a = np.delete(a, 0, 1)
  if '#' in s:
    a = np.append(a, s, axis=1)

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
b = []
li = [0] * w
for i in range(h):
    a = list(input())
    b.append(a)
    for j in range(w):
        if a[j] == "#":
            li[j] += 1

for i in range(h):
    if b[i].count(".") == w:
        continue
    for j in range(w):
        if li[j] != 0:
            print(b[i][j], end="")
    print("")

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
import copy

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

def p(arr,b="\n",e="\n"):
  print(b,end="")
  for i in arr:
    for j in i:
      print(j,end="")
    print()
  print(e,end="")

h,w = readInts()
a = [list(input()) for i in range(h)]

for i in range(h-1,-1,-1):
  boo = 1
  for j in range(w-1,-1,-1):
    if a[i][j]=="#":
      boo = 0
  if boo==1:
    del a[i]

for i in range(len(a[0])-1,-1,-1):
  boo = 1
  for j in range(len(a)-1,-1,-1):
    if a[j][i]=="#":
      boo = 0
  if boo==1:
    for j in range(len(a)-1,-1,-1):
      del a[j][i]

p(a,b="",e="")

Submission status: Accepted

Solution code:
import sys
H,W = map(int,input().split())
array_list = []
for I in range(H):
    array_list.append(list(map(str,input())))

if not ( 1 <= H <= 100 and 1 <= W <= 100 ):
    sys.exit()

Horizon_list = []
Vertical_list = []
# Horizon check
for J in range(len(array_list)):
    if array_list[J].count('.') == W:
        Horizon_list.append(J)
# Vertical check
list_check = [list(x) for x in zip(*array_list)]
for K in range(len(list_check)):
    if list_check[K].count('.') == H:
        Vertical_list.append(K)
# print result
for L in range(H):
    for M in range(W):
        if (L not in Horizon_list ) and (M not in Vertical_list):
            print(array_list[L][M],end='')
    print('\n')

Submission status: Accepted

Solution code:
import sys
H,W = map(int,input().split())
array_list = []
for I in range(H):
    array_list.append(list(map(str,input())))

if not ( 1 <= H <= 100 and 1 <= W <= 100 ):
    sys.exit()

# print(array_list)

Horizon_list = []
Vertical_list = []
# Horizon check
for J in range(len(array_list)):
    if array_list[J].count('.') == W:
        Horizon_list.append(J)
# Vertical check
list_check = [list(x) for x in zip(*array_list)]
for K in range(len(list_check)):
    if list_check[K].count('.') == H:
        Vertical_list.append(K)
# print(Horizon_list)
# print(Vertical_list)
for L in range(H):
    for M in range(W):
        if (L not in Horizon_list ) and (M not in Vertical_list):
            print(array_list[L][M],end='')
    print('\n')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
H,W = map(int,input().split()) 

S = []
for _ in range(H):
    S.append(list(input()))

R = []
C = []

for i in range(H):
    flag = 1
    for j in range(W):
        if S[i][j] == "#":
            flag = 0
            break
    if flag == 1:
        R.append(i)

for i in range(W):
    flag = 1
    for j in range(H):
        if S[j][i] == "#":
            flag = 0
            break
    if flag == 1:
        C.append(i)

C.sort(reverse=True)
R.sort(reverse=True)

if len(C)>0:
    for i in range(len(C)):
        for j in range(H):
            del S[j][C[i]]

if len(R)>0:
    for i in range(len(R)):
        del S[R[i]]

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

Submission status: Accepted

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

grid = []
del_cnt = 0
for i in range(h):
    row = input()
    if '#' in row:
        grid.append(row)
    else:
        del_cnt += 1
ans = []
for i in range(w):
    col = ""
    for j in range(h-del_cnt):
        col += grid[j][i]
    if '#' in col:
        ans.append(i)

for i in range(h-del_cnt):
    tmp = ""
    for a in ans:
        tmp += grid[i][a]
    print(tmp)

Submission status: Accepted

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

#print(a)

while 1:
  h, w = [0, 0]
  hl = []
  for i in range(len(a)):
    w = 0
    for j in range(len(a[0])):
      #print(i, j, a[i][j])
      if a[i][j] != '.':
        w += 1
    #print(w)
        
    if w == 0:
      hl.append(i)
      
  hl.sort(reverse = True)
  for i in hl:
    del a[i]
    
  wl = []
  for i in range(len(a[0])):
    h = 0
    for j in range(len(a)):
      if a[j][i] != '.':
        h += 1
    #print(h)
        
    if h == 0:
      wl.append(i)
      
  wl.sort(reverse = True)
  for i in wl:
    for j in range(len(a)):
      del a[j][i]
        
  if h != 0 and w != 0:
    break
    
for i in range(len(a)):
  print(''.join(a[i]))

Submission status: Accepted

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

row = []
col = []
for i in range(h):
  if a[i].count("#") == 0: row.append(i)
    
for i in range(w):
  for j in range(h):
    if a[j][i] == "#": break
  else: col.append(i)

for i in range(h):
  if i in row: continue
  ans = ""
  for j in range(w):
    if j in col: continue
    ans += a[i][j]
  print(ans)

Submission status: Accepted

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

row = [0] * h
column = [0] * w
for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            row[i] = 1
            column[j] = 1

for i in range(h):
    if row[i] == 1:
        for j in range(w):
            if column[j] == 1:
                print(field[i][j], end='')
        print()

Submission status: Accepted

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

remove_h = []
for i in range(h):
    if set(G[i]) == {"."}:
        remove_h.append(i)

remove_w = []
for j in range(w):
    if set([g[j] for g in G]) == {"."}:
        remove_w.append(j)

for i in range(h):
    if i not in remove_h:
        S = ""
        for j in range(w):
            if j not in remove_w:
                S += G[i][j]
        print(S)

Submission status: Accepted

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

for i in range(h):
    ls = list(input())
    if "#" in ls:
        l.append(ls)
        

s = [0]*w

for i in range(len(l)):
  for j in range(w):
    if l[i][j] == "#":
      s[j] = 1  

for i in range(len(l)):
  ans = ""
  for j in range(w):
    ans += l[i][j]*s[j]
  print(ans)

Submission status: Accepted

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

for i in range(h):
    ls = list(input())
    if "#" in ls:
        l.append(ls)
        for j in range(w):
            if ls[j] == "." and j not in r:
                r.append(j)

s = [i for i in range(w)]

for i in r:
  count = 0
  for j in range(len(l)):
    if l[j][i] == ".":
      count += 1
  if count == len(l):
    s.remove(i) 

ans = []
for i in range(len(l)):
  a = []
  for j in s:
    a.append(l[i][j])
  ans.append(a)
  

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

Submission status: Accepted

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

row=[]
col=[]
#行探索
for i in range(h):
    flg=0
    for j in range(w):
        if grid[i][j]=='#':
            flg=1

    if flg==0:
        row.append(i)

#列探索
for j in range(w):
    flg=0
    for i in range(h):
        if grid[i][j]=='#':
            flg=1

    if flg==0:
        col.append(j)

ans=[]
for i in range(h):
    arr=[]
    for j in range(w):
        if i in row or j in col:
            continue
        else:
            arr.append(grid[i][j])
    if len(arr)!=0:
        ans.append(arr)

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

Submission status: Accepted

Solution code:
def main():
    h,w=map(int,input().split())
    a = [list(input()) for _ in range(h)]
    b = []
    for i in a:
        if i.count(".") != w:
            b.append(i)
    for i in list(range(w))[::-1]:
        for j in b:
            if j[i] == "#":
                break
        else:
            for j in range(len(b)):
                del b[j][i]
    for x in b:
        print("".join(x))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
tmp = []
flag = True
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            flag = False
    if flag:
        tmp.append(i)
    flag = True
flag = True
tmp2 = []
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            flag = False
    if flag:
        tmp2.append(i)
    flag = True
t = set(tmp)
t2 = set(tmp2)
for i in range(h):
    for j in range(w):
        if i not in t and j not in t2:
            print(a[i][j],end='')
    if i not in t:
        print()

Submission status: Accepted

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

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


c = [list(x) for x in zip(*b)]
ans = []
for i in range(len(c)):
    if "#" in c[i]:
        ans.append(c[i])
        
ans = [list(x) for x in zip(*ans)]
for v in ans:
    print("".join(v))

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    a = [SS() for _ in range(H)]

    white_columun = set()
    for c in range(W):
        cnt = 0
        for r in range(H):
            if a[r][c] == '.':
                cnt += 1
        if cnt == H:
            white_columun.add(c)

    for i in a:
        if i.count('.') < W:
            ans = []
            for j in range(W):
                if not j in white_columun:
                    ans.append(i[j])
            print(''.join(ans))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(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())
lst = []
alldot = [True] * w
for i in range(h):
  s = input()
  if s.count('#') >= 1:
    lst.append(s)
    for t in range(w):
      alldot[t] = alldot[t] and s[t] == '.'
  else:
    h -= 1
res = [''] * h
for i in range(h):
  for j in range(w):
    if alldot[j]:
      pass
    else:
      res[i] += lst[i][j]
for i in res:
  print(i)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
list=[]
for i in range(h):
    a=input()
    if "#" in a:
        list.append(a)
h=len(list)
d=[0]*w
for i in range(h):
    for j in range(w):
        if list[i][j]=="#":
            d[j]=1
for i in range(h):
    ans=""
    for j in range(w):
        ans+=list[i][j]*d[j]
    print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


h, w = LI()
a = [list(S()) for _ in range(h)]
ans = [[a[j][i] for i in range(w)] for j in range(h)]
# is_white_line = [[False for _ in range(w)] for __ in range(h)]
# is_white_row = [[False for _ in range(h)] for __ in range(w)]

for i in range(h):
    is_white = True
    for j in range(w):
        if a[i][j] == '.':
            continue
        else:
            is_white = False
            break
    if is_white:
        ans[i] = [False] * w

for i in range(w):
    is_white = True
    for j in range(h):
        if a[j][i] == '.':
            continue
        else:
            is_white = False
            break
    if is_white:
        for j in range(h):
            # ans[i].pop(j)
            ans[j][i] = False

for i in range(w):
    is_white = True
    for j in range(h):
        if a[j][i] == '.':
            continue
        else:
            is_white = False
            break
    if is_white:
        for j in range(h):
            # ans[i].pop(j)
            ans[j][i] = False
res = ''
for i in range(h):
    if not(any(ans[i])):
        continue
    for j in range(w):
        if ans[i][j]:
            res += ans[i][j]
    res += '\n'
print(res.rstrip('\n'))

Submission status: Accepted

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

i = 0
while i < H:
    j = 0
    while j < W and A[i][j] == '.':
        j += 1
    if j >= W:
        for k in range(i, H - 1):
            for j in range(W):
                A[k][j] = A[k + 1][j]
        H -= 1
    else:
        i += 1
j = 0
while j < W:
    i = 0
    while i < H and A[i][j] == '.':
        i += 1
    if i >= H:
        for k in range(j, W - 1):
            for i in range(H):
                A[i][k] = A[i][k + 1]
        W -= 1
    else:
        j += 1
for i in range(H):
    for j in range(W):
        print(A[i][j], end='')
    print()

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
li=[]
for i in range(h):
  li.append(list(input()))
ll=[]
for i in li:
  if "#" in i:
    ll.append(i)
ll=np.array(ll).T.tolist()

out=[]
for i in ll:
  if "#" in i:
    out.append(i)
out=np.array(out).T.tolist()
for i in out:
  for j in i:
    print(j,end="")
  print()

Submission status: Accepted

Solution code:
# from pprint import pprint

# import math
# import collections

# n = int(input())
h, w = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))

a = []
for _h in range(h):
    a.append(list(input()))

mask = [[False] * w for h in range(h)]

# 行の判定
for i, row in enumerate(a):
    if all([True if c == '.' else False for c in a[i]]):
        mask[i] = [True] * w

# 列の判定
x = [True] * w
for row in a:
    for j, col in enumerate(row):
        if col == '.':
            x[j] = x[j] and True
        else:
            x[j] = x[j] and False

for i, row in enumerate(a):
    for j, _x in enumerate(x):
        if _x:
            mask[i][j] = True

for i in range(h):
    if all(mask[i]):
        continue
    p_row = ''.join([a[i][j] for j in range(w) if mask[i][j] is False])
    print(p_row)

Submission status: Accepted

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

compress_row = []

for i in range(h):
    if '#' not in a[i]:
        compress_row.append(i)

compress_col = []
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            break
    else:
        compress_col.append(i)

row = []
for i in range(h):
    col = []
    for j in range(w):
        if j in compress_col:
            continue
        col.append(a[i][j])
    if i in compress_row:
        continue
    row.append(col)

print(*[''.join(r) for r in row], sep='\n')

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [input() for _ in range(H)]
A = list(filter(lambda a: any(x=='#' for x in a), A)) 
A = list(filter(lambda a: any(x=='#' for x in a), zip(*A)))

for a in zip(*A):
  print("".join(a))

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
A = [input() for h in range(H)]
row = H*[False]
col = W*[False]

for h in range(H):
  for w in range(W):
    if A[h][w]=="#":
      row[h] = True
      col[w] = True

for h in range(H):
  if row[h]:
    for w in range(W):
      if col[w]:
        print(A[h][w],end="")
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
    b = input()
    count = b.count('.')
    if count == W:
        continue
    else:
        a += [list(map(str, b))]

num = len(a)
val = []
for i in range(W):
    for j in range(num):
        if a[j][i] == '.':
            if j == num-1:
                val.append(i)
            else:
                continue
        else:
            break
for i in reversed(val):
    for j in range(num):
        del a[j][i]
for i in range(len(a)):
    print(''.join(a[i]))

Submission status: Accepted

Solution code:
y,x=map(int,input().split())
lst=[]
for i in range(y):
    lst.append(input())
    
del_line=[]
del_row=[]
for i in range(y):
    cnt=0
    for j in range(x):
        if lst[i][j]==".":
            cnt+=1
    if cnt==x:
        del_line.append(i)
for i in range(x):
    cnt=0
    for j in range(y):
        if lst[j][i]==".":
            cnt+=1
    if cnt==y:
        del_row.append(i)

for i in range(y):
    if not i in del_line:
        pr=[]
        for j in range(x):
            if not j in del_row:
                pr.append(lst[i][j])
        print("".join(pr))

Submission status: Accepted

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

removed_rows = []
removed_cols = []
for row in range(1, H+1):
    is_all_dot = 1
    for col in range(1, W+1):
        if a[row][col] == "#":
            is_all_dot = 0
    if is_all_dot:
        removed_rows.append(row)
for col in range(1, W+1):
    is_all_dot = 1
    for row in range(1, H+1):
        if a[row][col] == "#":
            is_all_dot = 0
    if is_all_dot:
        removed_cols.append(col)

for row in range(1, H+1):
    if row in removed_rows:
        continue
    for removed_col in removed_cols:
        a[row][removed_col] = ""
    ans = "".join(a[row][1:])
    print(ans)

Submission status: Accepted

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

rowIndex=[False]*h
colIndex=[False]*w

for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            rowIndex[i]=True
            colIndex[j]=True
    
for i in range(h):
    if rowIndex[i]:
        for j in range(w):
            if colIndex[j]:
                print(a[i][j],end='')
        print()

Submission status: Accepted

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

new_a= np.empty((0,len(a[0])), dtype='<U1')
for i in a:
    if "#" in i:
        new_a = np.append(new_a, [i], axis=0)
a = new_a.T
new_a= np.empty((0,len(a[0])), dtype='<U1')
for i in a:
    if "#" in i:
        new_a = np.append(new_a, [i], axis=0)
a = new_a.T
for i in a:
    print("".join(i))

Submission status: Accepted

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

# 行、列に黒が存在するならTrue
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
# print(row)
# print(col)

for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                # 一つずつprintすると改行されてしまう
                # end="" で改行しないようにする
                print(a[i][j], end='')
        print()  # print() で改行、次のrowへ

Submission status: Accepted

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

b = []
for i in range(h):
  if a[i].count('.') != w:
    b.append(a[i])
  else:
    h -= 1

c = [''] * h
for i in range(w):
  x = [row[i] for row in b] 
  if x.count('.') != h:
    for j in range(h):
      c[j] = c[j] + x[j]
    
for i in c:
  print(i)

Submission status: Accepted

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

for i in range(h):
    s = input()
    if s != "."*w:
        a.append(s)

l = len(a)

ans = [[] for i in range(l)]

for i in range(w):
    for j in range(l):
        if a[j][i] == "#":
            for k in range(l):
                ans[k].append(a[k][i])
            break
for i in range(l):
    print("".join(ans[i]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(H):
    if list(set(a[i])) != ["."]:
        counter.append(list(a[i]))

b = list(zip(*counter))
banswer = []

for i in range(W):
    if list(set(b[i])) != ["."]:
        banswer.append(list(b[i]))

answer = list(zip(*banswer))

for j in answer:
    result = "".join(j)
    print(result)

Submission status: Accepted

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

row = [False] * h # 行
col = [False] * w # 列

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

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

H,W = I()
S = []
for i in range(H):
    s1 = list(s())
    if '#' in s1:
        S.append(s1)
L = [1]*W
for i in range(len(S)):
    if 1 not in L:
        break
    for j in range(W):
        if S[i][j] == '#':
            L[j] = 0
for i in range(W-1,-1,-1):
    if L[i] == 1:
        for j in range(len(S)):
            S[j].pop(i)
for i in range(len(S)):
    print(''.join(S[i]))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
dh = []
dw = []
for i in range(h):
  if not('#' in a[i]):
    dh.append(i)
for j in range(w):
  cal = ''
  for k in range(h):
    cal += a[k][j]
    if k == h-1 and not('#' in cal):
      dw.append(j)

for hl in sorted(dh, reverse=True):
  a.pop(hl)

for wl in sorted(dw, reverse=True):
  for i in range(h-len(dh)):
    a[i].pop(wl)

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
field = []
for i in range(h):
  field.append(list(input()))
tfield = [x for x in zip(*field)]
wh = []
ww = []

for i in range(h):
  if len(set(field[i])) == 1 and field[i][0] == ".":
    wh.append(i)

for i in range(w):
  if len(set(tfield[i])) == 1 and tfield[i][0] == ".":
    ww.append(i)

for i in range(h):
  if i in wh:
    continue
  for j in range(w):
    if j not in ww:
      print(field[i][j], end="")
  print("")

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    h, w = map(int, input().split())
    map=[]
    for i in range(h):
        a=input()
        map.append(a)
    checkH=[False]*h
    checkW=[False]*w

    for i in range(h):
        for j in range(w):
            if map[i][j] =="#":
                checkH[i]=True
                checkW[j] = True

    for i in range(h):
        ans=""
        for j in range(w):
            if checkH[i] ==True and checkW[j]==True:
                ans+=map[i][j]
        if ans != "":
            print(ans)

Submission status: Accepted

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

l=[]
for i in range(h):
    a=input()
    if "#" in a:
        l.append(a)


r=[]
for i in range(w):
    for k in l:
        if k[i]=="#":
            r.append(i)
            break
n=len(l)
new_l=[]

for i in range(n):
    s=""
    for k in r:
        s=s+l[i][k]
    new_l.append(s)

for i in new_l:
    print(i)

Submission status: Accepted

Solution code:
import numpy as np
n,m=map(int,input().split())
arr=[]
for i in range(n):
    l=[ord(c)-46 for c in input()]
    if l.count(0)==m:
        continue
    arr.append(l)
a=np.array(arr)
a=a.T
b=[]
for i in range(len(a)):
    if list(a[i]).count(0)==len(a[i]):
        continue
    b.append(list(a[i]))
b=list(np.array(b).T)
for l in b:
    for x in l:
        if x==0:
            print(".",end="")
        else:
            print("#",end="")
    print()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

A = [0] * H
for i in range(H):
    A[i] = list(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 not row[i]:
        continue
    for j in range(W):
        if not col[j]:
            continue
        print(A[i][j], end="")
    print()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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


x = set()
for i in range(H):
    if all(True if a == '.' else False for a in A[i]):
        x.add(i)

ans = []
for i in range(H):
    if i in x:
        continue
    ans.append(A[i])

A = ans
x = set()
for i in range(W):
    if all(True if A[j][i] == '.' else False for j in range(len(A))):
        x.add(i)

ans = []
for i in range(len(A)):
    z = []
    for j in range(W):
        if j not in x:
            z.append(A[i][j])
    ans.append(z)

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

Submission status: Accepted

Solution code:
def imp():return map(int,input().split())
h,w=imp()
l=[]
for _ in range(h):
    s=input()
    if '#' in s:l.append([x for x in s])

ans=[]
for j in range(w):
    s=""
    for i in range(len(l)):
        s+=l[i][j]
    if '#' in s: ans.append([x for x in s])

w=len(ans[0])
for j in range(w):
    s=""
    for x in ans:
        s+=x[j]
    print(s)

Submission status: Accepted

Solution code:
from functools import reduce
from decimal import *
from operator import mul

def main():
    h, w = input_list()
    masu = []
    for _ in range(h):
        line = list(input())
        masu.append(line)
    rows = [False] * h
    cols = [False] * w
    for i, m in enumerate(masu):
        for j, v in enumerate(m):
            if v == "#":
                rows[i] = True
                cols[j] = True
    for i, m in enumerate(masu):
        if rows[i] is False:
            continue
        a = ''
        for j, v in enumerate(m):
            if cols[j] is False:
                continue
            a += v
        print(a)

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in  range(h):
    k = input()
    if "#" in k:
        a.append([i for i in k])
        
import numpy as np
for i in np.array([i for i in np.array(a).T if "#" in i]).T.tolist():
    print("".join(i))