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())
lst = []
for _ in range(H):
    s = input()
    if s.find('#') >= 0:
        lst.append(s)

lst2 = []
for w in range(W):
    skip = True
    for h in range(len(lst)):
        if lst[h][w] == '#':
            skip = False
            break
    lst2.append(skip)

for x in lst:
    for idx, y in enumerate(x):
        if not lst2[idx]:
            print(y, end='')
    print()

Submission status: Accepted

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

    for i in range(h):
        a = input()
        s = set()
        for i in range(w):
            if a[i] == ".":
                s.add(i)
        S = S & s
        if len(s) != w:
            A.append(a)
    
    for word in A:
        print_w = ""
        for i in range(w):
            if not(i in S):
              print_w += word[i]
        print(print_w)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for j in range(len(grid[0])):
    is_all_white = True
    column = []
    for i in range(len(grid)):
        column.append(grid[i][j])
        if grid[i][j] != ".":
            is_all_white = False
    if(not is_all_white):
        grid2.append(column)

for j in range(len(grid2[0])):
    is_all_white = True
    column = []
    for i in range(len(grid2)):
        column.append(grid2[i][j])
        if grid2[i][j] != ".":
            is_all_white = False
    if(not is_all_white):
        grid3.append(column)

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

Submission status: Accepted

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

out2 = ["" for j in range(len(out))]
blankLine = ""
for i in range(len(out)):
    blankLine += "."
for j in range(w):
    strTmp = ""
    for i in range(len(out)):
        strTmp += out[i][j]
    if strTmp != blankLine:
        for i in range(len(out)):
            out2[i] += out[i][j]
for i in range(len(out2)):
    print(out2[i])

Submission status: Accepted

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

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

H=len(A)
B=[[] for _ in range(H)]
X=[[] for i in range(W)]

for i in range(W):
	for j in range(H):
		X[i].append(A[j][i])

while ["." for p in range(H)] in X:
	X.remove(["." for c in range(H)])

W=len(X)
for i in range(H):
	for j in range(W):
		B[i].append(X[j][i])

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

Submission status: Accepted

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

a = []
b = []
c = []

for i in range(H):
  a1 = input()
  if('#' in a1):
     a.append(a1)
        
  else:
      continue

a = list(zip(*a))
l1 = len(a)
         
for j in range(l1):
  b1 = a[j]
   
  if( '#' in b1):
      b.append(b1)
  
  else:
      continue
         
c = list(zip(*b))
l2 = len(c)

for n in range(l2):
         print("".join(c[n]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    tmp = list(input())
    if tmp[0] != '.' or tmp.count('.') != len(tmp):
        a.append(tmp)
b = []
for j in range(w):
    f = True
    for k in range(len(a)):
        if a[k][j] == '#':
            f = False
    else:
        if f:
            b.append(j)
for x in range(len(a)):
    for y in range(len(a[x])):
        if y not in b:
            print(a[x][y], end='')
    else:
        print('')

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:
h,w = map(int, input().split())
cells = [[c for c in row] for row in [input() for i in range(h)] if '#' in row]

h = len(cells)
for i in range(w-1, -1, -1):
  has_block = False
  for j in range(h):
    if cells[j][i] == '#':
      has_block = True
      break
  if not has_block:
    for j in range(h):
      cells[j].pop(i)
  

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

Submission status: Accepted

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

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

c = [[] for _ in range(len(b))]
for j in range(W):
    if any(["#" == b[i][j] for i in range(len(b))]):
        for i in range(len(b)):
            c[i].append(b[i][j])

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

Submission status: Accepted

Solution code:
H, W =  [int(item) for item in input().split()]
hl = [0] * H
wl = [0] * W
m = []
for h in range(H):
  rows = input().rstrip()
  m.append(rows)
  for w in range(W):
    if rows[w] == ".":
      hl[h] += 1
      wl[w] += 1

for h in range(H):
  if not hl[h] == W :
    for w in range(W):
      if not wl[w] == H:
        print(m[h][w], end="")
    print("")

Submission status: Accepted

Solution code:
H,W = map(int,input().split(" "))
table = []
for i in range(H):
  table.append(list(input()))
row = [False]*H
col = [False]*W
for i in range(H):
  for j in range(W):
    if table[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(table[i][j],end='')
    print()

Submission status: Accepted

Solution code:
hw = list(map(int, input().split()))
h = hw[0]
w = hw[1]
a = list()
for i in range(h):
    a.append(list(input()))
h_blank = list()
w_blank = list()
for i in range(h):
    flag = 0
    if not "#" in a[i]:
        h_blank.append(i)
for i in range(w):
    flag = 0
    for j in range(h):
        if a[j][i] == "#":
            break
        flag += 1
    if flag == h:
        w_blank.append(i)
x = 0
for i in h_blank:
    a.pop(i - x)
    x += 1
for i in range(h - x):
    y = 0
    for j in w_blank:
        a[i][j] = ""
        y += 1
for i in a:
    print("".join(i))

Submission status: Accepted

Solution code:
import sys

H, W = map(int, input().split())
a = [line for line in sys.stdin.readlines()]

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

for i, temp_row in enumerate(a):
    for j, c in enumerate(temp_row):
        if c == "#":
            row[i] = True
            column[j] = True

for i, exist_row in enumerate(row):
    if not exist_row:
        continue
    for j, exist_column in enumerate(column):
        if exist_column:
            print(a[i][j], end = "")
    print()

Submission status: Accepted

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

lis = []
whitecol = [0]*W
for i in range(H):
    t = input()
    if '#' in t:
        lis.append(list(t))
        for j in range(len(t)):
            if t[j] == '#':
                whitecol[j] = 1
for i in lis:
    print(''.join([j for j,k in zip(i,whitecol) if k]))

Submission status: Accepted

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

for i in range(H):
    row = list(input())
    if "#" in row:
        grid.append(row)

h = len(grid)
for j in range(W):
    cnt = 0
    for i in range(h):
        if grid[i][j] == "#":
            cnt += 1
    if cnt <= 0:
        for i in range(h):
            grid[i][j] = "x"

for i in range(h):
    row = ""
    for j in range(W):
        if grid[i][j] != "x":
            row += grid[i][j]
    print(row)

Submission status: Accepted

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

for y in range(H) :
    for x in range(W) :
        if L[y][x] == "#" :
            X[x] = True
            Y[y] = True

for y in range(H) :
    if Y[y] == True :
        ANS = []
        for x in range(W) :
            if X[x] == True :
                ANS.append(L[y][x])
        print("".join(ANS))

Submission status: Accepted

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

l = []

for i in range(h):
    l.append(list(input()))
flag = False

while not flag:
    f2=True
    for i in range(h):
        if len(set(l[i])) == 1 and l[i][0]=='.':
            l.pop(i)
            f2=False
            break
    
    h=len(l)
    w=len(l[0])

    for j in range(w):
        f3=True
        for i in range(h):
            f3 = f3 and l[i][j]=='.'
        if f3:
            for i in range(h):
                l[i].pop(j)
            f2=False
            break
    h=len(l)
    w=len(l[0])
    flag = f2

for i in range(len(l)):
    s = ''
    for j in range(len(l[0])):
        s+=l[i][j]
    print(s)

Submission status: Accepted

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

a = [i for i in As if "#" in i]
b = ["".join(j[i] for j in a) for i in range(W)]
b_ = [i for i in b if "#" in i]
a_ = ["".join(j[i] for j in b_) for i in range(len(b_[0]))]

for i in a_:
  print(i)

Submission status: Accepted

Solution code:
def main():
    h, w = map(int, input().split())
    rows = set()
    cols = set()

    d = []
    for i in range(h):
        s = input()
        d.append(s)
        for j, c in enumerate(s):
            if c == '#':
                rows.add(i)
                cols.add(j)

    for i in range(h):
        if i not in rows:
            continue
        print(''.join(c for j, c in enumerate(d[i]) if j in cols))

main()

Submission status: Accepted

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

new_field=[]
for i in range(H):
    for j in range(W):
        if(field[i][j]=="#"):
            new_field.append(field[i])
            break

new_new_field=[]
for i in range(W):
    tmp=[]
    flag=0
    for j in range(len(new_field)):
        if(new_field[j][i]=="#"):
            flag=1
        tmp.append(new_field[j][i])
    if(flag==1):
        new_new_field.append(tmp)

for i in range(len(new_new_field[0])):
    for j in range(len(new_new_field)):
        print("{}".format(new_new_field[j][i]),end="")
    print()

Submission status: Accepted

Solution code:
import sys


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

    rd = [False] * h
    cd = [False] * w

    for i in range(h):
        rd[i] = all(a[i][j] == '.' for j in range(w))

    for j in range(w):
        cd[j] = all(a[i][j] == '.' for i in range(h))

    for i in range(h):
        line = ''
        for j in range(w):
            if rd[i] or cd[j]:
                continue
            line += a[i][j]
        if line:
            print(line)


main()

Submission status: Accepted

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

for i in range(h):
    a = input()
    s.append([str(m) for m in list(str(a))])

coi = 0
p = len(s)
for i in range(h):
    i = i - coi
    """if i > len(s) - 1 - coi:
        break"""
    #for j in range(w):
    if "#" not in s[i]:
        s.pop(i)
        p = len(s)
        coi += 1

coj = 0
for j in range(w):
    j = j - coj
    for i in range(len(s)):
        """if j > len(s[0]) - 1 - coj:
            break"""
        if "#" == s[i][j]:
            break
        if "." == s[i][j] and i == len(s) - 1:
            for m in range(len(s)):
                s[m].pop(j)
            coj += 1

t = []

for i in range(len(s)):
    t.append( ''.join(s[i]))

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    H, W = map(int, input().split())
    field = []
    for i in range(H):
        s = input()
        if s.count("#") != 0:
            field.append(s)

    ans = [""] * len(field)
    for x in range(W):
        ok = False
        for y in range(len(field)):
            ok |= field[y][x] == "#"

        if ok:
            for y in range(len(field)):
                ans[y] += field[y][x]

    print("\n".join(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h, w = map(int, raw_input().split())
arr = []
del_row = 0
for i in range(h):
    row = raw_input()
    if row != ("."*w):
        arr.append(row)
    else:
        del_row += 1
ans = []
for j in range(w):
    column = []
    for k in range(h-del_row):
        column.append(arr[k][j])
    if column != ["." for i in range(h-del_row)]:
        ans.append(column)
for num in range(h-del_row):
    str = ""
    for lst in ans:
        str += lst[num]
    print str

Submission status: Accepted

Solution code:
def grid_compression(a, h, w):
    hh = []
    for i in range(h):
        ok = True
        for j in range(w):
            if a[i][j] == '#':
                ok = False
                break
        if ok:
            hh += [i]
    ww = []
    for i in range(w):
        ok = True
        for j in range(h):
            if a[j][i] == '#':
                ok = False
                break
        if ok:
            ww += [i]
    aa = []
    for i in range(h):
        if i in hh:
            continue
        aa.append('')
        for j in range(w):
            if j in ww:
                continue
            aa[-1] += a[i][j]
    return '\n'.join(aa)

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

Submission status: Accepted

Solution code:
n = list(map(int, input().split()))
H, W = n[0], n[1]
li = [['.' for i in range(W)] for i in range(H)]

for i in range(H):
    l = input()
    for j in range(len(l)):
        li[i][j] = l[j]

pos = []
# horizontal check
for i in range(H):
    c = 0
    for j in range(W):
        if li[i][j] == '.':
            c += 1
    if c == W:
        pos.append(i)

j = 0
for i in range(len(pos)):
    li.pop(pos[i]-j)
    j += 1


pos = []
# vertical check
for i in range(len(li[0])):
    c = 0
    for j in range(len(li)):
        if li[j][i] == '.':
            c += 1
    if c == len(li):
        pos.append(i)

for i in range(len(li)):
    m = 0
    for x in range(len(pos)):
        li[i].pop(pos[x]-m)
        m += 1

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
lst=list(input() for i in range(h))
n_h=h
for i in range(len(lst)):
    if "#" not in lst[h-i-1]:
        n_h-=1
        lst.pop(h-i-1)
lst=list(map(list,lst))
for i in range(w):
    T=True
    for b in range(n_h):
        if lst[b][w-i-1]=="#":
            T=False
            break
    if T:
        for b in range(n_h):
            lst[b].pop(w-i-1)
for a in lst:
    print("".join(a))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
lst=list(input() for i in range(h))
n_h=h
for i in range(len(lst)):
    if "#" not in lst[h-i-1]:
        n_h-=1
        lst.pop(h-i-1)
h=n_h
n_w=w
lst=list(map(list,lst))
for i in range(w):
    T=True
    for b in range(h):
        if lst[b][w-i-1]=="#":
            T=False
            break
    if T:
        for b in range(h):
            lst[b].pop(w-i-1)
            n_w-=1
for b in range(h):
    print("".join(lst[b]))

Submission status: Accepted

Solution code:
import copy
h,w=map(int,input().split())
a=[]
deleted=0
for i in range(h):
    l=list(input())
    for j in l:
        if j=='#':
            a.append(l)
            break
    else:
        deleted+=1
h-=deleted

deleted=0
b=copy.deepcopy(a)
for i in range(w):
    for j in range(h):
        if a[j][i]=='#':
            break
    else:
        for j in range(h):
            b[j].pop(i-deleted)
        deleted+=1

s=''
for i in b:
    s+=''.join(i)+'\n'
print(s)

Submission status: Accepted

Solution code:
H,W=(int(i) for i in input().split(' '))
grid=[]
delete_count= 0
pop_count=0
for h in range(H):
  tmp = [char for char in input()]
  if tmp.count('#')!=0:
    grid.append(tmp)
  else:
    delete_count += 1
for w in range(W):
  check = 0
  for h in range(H-delete_count):
    if grid[h][w-pop_count]=='#':
      check = 1
  if check == 0:
    for h in range(H-delete_count):
      del grid[h][w-pop_count]
    pop_count+=1
for h in range(H-delete_count):
  grid[h]=''.join(grid[h])
  print(grid[h])

Submission status: Accepted

Solution code:
from sys import stdin


def main() -> None:
    h = next_int()
    w = next_int()
    a = [input() for _ in range(h)]

    for j in range(w - 1, -1, -1):
        flg = False
        for i in range(h):
            if a[i][j] == "#":
                flg = True

        if not flg:
            for i in range(h):
                a[i] = a[i][:j] + a[i][j + 1:]

    for i in range(h):
        if "#" in a[i]:
            print(a[i])


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h, w=map(int, input().split())
s=[input() for i in range(h)]
nuee1=[]
nuee2=[]
for i in range(h):
  nuee=False
  for j in range(w):
    if s[i][j]=='#':
      nuee=True
      break
  nuee1.append(nuee)
for j in range(w):
  nuee=False
  for i in range(h):
    if s[i][j]=='#':
      nuee=True
      break
  nuee2.append(nuee)
for i in range(h):
  if not nuee1[i]:
    continue
  for j in range(w):
    if not nuee2[j]:
      continue
    print(s[i][j], end="")
  print()

Submission status: Accepted

Solution code:
tate,yoko=map(int,input().split())
b=[]
for i in range(tate):
  b.append(list(input()))
tatecheck=[]
for i in range(tate):
  flag=1
  for j in range(yoko):
    if b[i][j]=='#':
      flag=0
      break
  if flag==1:
    tatecheck.append(i)
tatecheck.reverse()
for i in tatecheck:
  del b[i]
yokocheck=[]
tate=len(b)
yoko=len(b[0])
for i in range(yoko):
  flag=1
  for j in range(tate):
    if b[j][i]=='#':
      flag=0
      break
  if flag==1:
    yokocheck.append(i)
yokocheck.reverse()
for i in yokocheck:
  for j in range(tate):
    del b[j][i]
tate=len(b)
for i in range(tate):
  print("".join(b[i]))

Submission status: Accepted

Solution code:
import numpy as np
H, W = [int(i) for i in input().split()]
ai = [list(input()) for i in range(H)]
arr = np.asarray(ai)
for x in range(H):
  if '#' not in arr[x,:]:
    arr[x,:] = 'a'
for y in range(W):
  if '#' not in arr[:,y]:
    arr[:,y] = 'a'
for x in range(H):
  str = ''
  for y in range(W):
    if arr[x,y] != 'a':
      str += arr[x,y]
    else:
      pass
  if str != '':
    print(str)
  else:
    pass

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
board=[""]*h
for i in range(h):
    board[i]=input()
boolx=[0]*h
booly=[0]*w
for i in range(h):
    for j in range(w):
        if board[i][j]=="#":
            boolx[i]=1
            booly[j]=1
for i in range(h):
    if boolx[i]:
        for j in range(w):
            if booly[j]:
                print(board[i][j],end="")
        print()

Submission status: Accepted

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

for h in range(H):
    temp = []
    line = input()
    for w in range(W):
        temp.append(line[w])
    grid.append(temp)

for h in range(H):
    if all([grid[h][w] == '.' for w in range(len(grid[h]))]):
        for w in range(len(grid[h])):
            grid[h][w] = ''

for w in range(W):
    if all([grid[h][w] in ('', '.') for h in range(len(grid))]):
        for h in range(len(grid)):
            grid[h][w] = ''

for h in range(len(grid)):
    if not all([grid[h][w] == '' for w in range(len(grid[h]))]):
        print(''.join(grid[h]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [input() for i in range(H)]
i = 0
while i<H:
    if not '#' in a[i]:
        del a[i]
        H -= 1
        i -= 1
    i += 1
a = list(map(list,zip(*a)))
i = 0
while i<W:
    if not '#' in a[i]:
        del a[i]
        W -= 1
        i -= 1
    i += 1
a = (list(map(list,zip(*a))))
for i in range(H):
    print(''.join(a[i]))

Submission status: Accepted

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

def turnover(hw):
    l1 = len(hw)
    l2 = len(hw[0])
    wh = ['' for _ in range(l2)]
    for i in range(0, l1):
        for j in range(0, l2):
            wh[j] += hw[i][j]
    return wh

def adjustHeight(hw):
    l2 = len(hw[0])
    for i in range(0, len(hw)):
        if hw[i] == '.' * l2:
            del hw[i]
            return adjustHeight(hw)
    return hw

def adjustWidth(hw):
    wh = turnover(hw)
    return turnover(adjustHeight(wh))

[print(_) for _ in adjustWidth(adjustHeight(a))]

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
a = np.zeros([h, w], dtype=int)
idx_h = []
idx_w = []
for i in range(h):
    s = input()
    v = list(map(int, s.replace('.', '1 ').replace('#', '-1 ').split()))
    if sum(v) != w:
        a[i, :] = v
        idx_h.append(i)
aa = np.sum(a, axis=0)
for i in range(w):
    if aa[i] != len(idx_h):
        idx_w.append(i)
for i in idx_h:
    s = ''
    for j in idx_w:
        if a[i, j] == 1:
            s += '.'
        elif a[i, j] == -1:
            s += '#'
    print(s)

Submission status: Accepted

Solution code:
import sys

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

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

skipedIdx_I = set()
skipedIdx_J = set()

# print(a)

for i in range(H):
    skip = True
    for j in range(W):
        if a[i][j] == "#":
            skip = False
    if skip == True:
        skipedIdx_I.add(i)

for j in range(W):
    skip = True
    for i in range(H):
        if a[i][j] == "#":
            skip = False
    if skip == True:
        skipedIdx_J.add(j)

# print(skipedIdx_I)
# print(skipedIdx_J)

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

sys.exit(0)

Submission status: Accepted

Solution code:
def adjust(array):
    # 調整
    re_array = []
    for arr in array:

        # 集合を取る #と.のみ
        a = set(arr)

        # 集合が１つで.だけのとき
        if len(a) == 1 and ''.join(a) == '.':
            continue

        else:
            re_array.append(arr) # 配列にapeendで配列を入れている
    return re_array


# 入力
H, W = map(int, input().split())
array = [list(input()) for _ in range(H)]

# 横
array = adjust(array)

# 縦
array = list(zip(*array)) # 転置する
array = adjust(array)

# 戻す
array = list(zip(*array))

# 出力
for arr in array:
    print(''.join(arr))

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 #同じ行か列に＃があるところは全て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:
n, m = map(int, input().split())
s = []
a = []
for _ in range(n):
    x = input()
    if '#' in x:
        s.append(x)
for j in range(m):
    res = False
    for x in s:
        if x[j] == '#':
            res = True
            break
    a.append(res)
s = ["".join(x[i] for i in range(m) if a[i]) for x in s]

for x in s:
    print(x)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
h,w  = map(int, input().split())
s=[]
for i in range(0,h):
  s.append(input())

b=[]
for i in range(0,w):
  f=False
  for j in range(0,h):
    if s[j][i]=='#':
      f=True
  b.append(f)

for j in range(0,h):
  if s[j].count('#')==0:
    continue
  res=""
  for i in range(0,w):
    if b[i]:
      res=res+s[j][i]
  print(res)

Submission status: Accepted

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

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

for i in range(h):
  for j in range(w):
    if area[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(area[i][j], end='')

    print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
map_ = list()
for i in range(h):
    map_.append(list(input()))
flag = True
while flag:

    flag = False

    for ii in range(len(map_)):
        if set(map_[ii]) == {"."}:
            del map_[ii]
            flag = True
            break

    map_t = [list(x) for x in zip(*map_)]

    for ii in range(len(map_t)):
        if set(map_t[ii]) == {"."}:
            del map_t[ii]
            flag = True
            map_ = [list(x) for x in zip(*map_t)]
            break

    map_ = [list(x) for x in zip(*map_t)]

for iiii in map_:
    print(*iiii,sep="")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
ans = []
for i in range(H):
    a.append(input())
    
    if len(set(a[-1])) == 1 and a[-1][0] == '.':
        del a[-1]

if len(a) == 1:
    kotae = a[0]
    kotae = kotae.replace('.', '')
    print(kotae)
else:
    for x in range(W):
        check = []
        for y in range(len(a)):

            if a[y][x] != '.':
                break
            else:
                check.append(a[y][x])
                
        if len(check) == len(a):
            ans.append(x)
            
    
    if len(ans) >= 1:
        re_ans = []
        for i in a:
            kari = list(i)
            for j in ans:
                kari[j] = '0'
           # print(kari)
            re_ans.append(kari)
        
        for i in re_ans:
            moji = ''.join(i)
            mojji = moji.replace('0', '')
            print(mojji)
    else:
        for i in a:
            print(i)

Submission status: Accepted

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

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

for i in range(W):
	emp=1
	for j in range(H):
		if(board[j][i]=='#'):
			emp=0
	if(emp==1):
		for j in range(H):
			board[j][i]='0'
			
for i in range(H):
	out=""
	for j in range(W):
		out+=board[i][j] if board[i][j]!='0' else ""
	if out!="":
		print(out)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[c for c in input()] for _ in range(h)]
b=[]
flag=0
for s in a:
  if "#" in s:
    b.append(s)
for i in range(w):
  flag=0
  for j in range(len(b)):
    if b[j][i]=="#":
      flag=1
      break
  if flag==0:
    for j in range(len(b)):
      b[j][i]=""
for s in b:
  print("".join(s))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[input() for i in range(H)]
for i in range(2):
    a=filter(lambda x:"#"in x,a)
    a=list(zip(*[list(_) for _ in a]))
print("\n".join(["".join(i) for i in a]))

Submission status: Accepted

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

new_list = []

H_del = []
W_del = []

#削除する行列の探索
for i in range(H):
    if list[i] == '.'*W:
        W_del.append(i)

for i in range(W):
    H_stock = ''
    for j in range(H):
        H_stock += list[j][i]
        if H_stock == '.'*H:
            H_del.append(i)

#削除する行列を除いた行列を再作成
for i in range(H):
    if i not in W_del:
        W_list = ''
        for j in range(W):
            if j not in H_del:
                W_list += list[i][j]
        new_list.append(W_list)

#答えを表示
for i in range(len(new_list)):
    print(new_list[i])

Submission status: Accepted

Solution code:
from collections import Counter
H, W = list(map(int, input().split()))
board = [list(input()) for _ in range(H)]
board = [b for b in board if b.count('.') < W]

b_r = []

for i in range(len(board[0])):
    r = [b[i] for b in board]
    b_r.append(r.count('.'))

idx = [i for i, x in enumerate(b_r) if x == len(board)]

for n in idx[::-1]:
    for b in board:
        b.pop(n)

for b in board:
    print(*b, sep='')

Submission status: Accepted

Solution code:
import numpy as np

def a(mat):
    new = []
    tmp_mat = mat.T
    for row in tmp_mat:
        if len(set(row)) == 1 and row[0] == '.':
            continue
        new.append(row)
    new = np.array(new)
    return new.T.tolist()





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

# matrix
results = []



for _ in range(h):
    row = list(input())
    if ''.join(row) == '.'*w:
        continue
    results.append(row)

results = np.array(results)

for row in a(results):
    print(''.join(row))

Submission status: Accepted

Solution code:
def t(A):
    ret = []
    for i in range(len(A[0])):
        r = []
        for j in range(len(A)):
            r.append(A[j][i])
        ret.append("".join(r))
    return ret

def d(A):
    ret = []
    for r in A:
        if r.count("#") > 0:
            ret.append(r)
    return ret

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

A = t(d(A))
A = t(d(A))
for r in A:
    print(r)