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:
#!/usr/bin/env python3



# 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 = []
    for i in range(H):
        A.append(list(input()))

    B = list(zip(*A))

    AA = []
    for a in A:
        AA.append(all(x == "." for x in a))

    BA = []
    for b in B:
        BA.append(all(x == "." for x in b))

    for a,aa in zip(A,AA):
        if not aa:
            for b,ba in zip(a,BA):
                if not ba:
                    print(b,end="")
            print("")




    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
hl=[]
wl=[]
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            hl.append(i)
            wl.append(j)
for i in set(hl):
    for j in set(wl):
        print(a[i][j],end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
blankw = [True] * w
blankh = [False] * h
data = []
for i in range(h):
    s = input()
    line = []
    if s.find("#") == -1:
        blankh[i] = True
    for j in range(w):
        line.append(s[j])
        if s[j] == "#":
            blankw[j] = False
    data.append(line)

for i in range(h):
    if blankh[i] is True:
        continue
    for j in range(w):
        if blankw[j] is True:
            continue
        print(data[i][j], end="")

    print("")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
field = []
hstack, wstack = set(), set()

for i in range(h):
    a = input()
    field.append(a)
    for j in range(w):
        if a[j] == '#':
            hstack.add(i)
            wstack.add(j)

hstack = sorted(list(hstack))
wstack = sorted(list(wstack))

for i in hstack:
    out = ""
    for j in wstack:
        out += field[i][j]
    print(out)

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:
import numpy as np

h, w = map(int, input().split())
grid = np.array([[j for j in input()] for i in range(h)])
grid = np.array([x for x in grid if "#" in x])
grid = np.array([x for x in grid.T if "#" in x])

[print("".join(x)) for x in grid.T]

Submission status: Accepted

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

H, W = map(int, input().split())
arr = [[j for j in input().rstrip()] for i in range(H)]
b = [x for x in arr if '#' in x]
c = zip(*[x for x in zip(*b) if '#' in x])
for x in c:
  print("".join(x))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Grid Compression
https://atcoder.jp/contests/abc107/tasks/abc107_b

"""
import sys


def solve(H, W, grid):
    res = [row for row in grid if not(len(set(row)) == 1 and row[0] == '.')]
    return list(zip(*[row for row in list(reversed([list(m) for m in zip(*res)])) if not (len(set(row)) == 1 and row[0] == '.')][::-1]))


def main(args):
    H, W = map(int, input().split())
    grid = [list(input()) for _ in range(H)]
    ans = solve(H, W, grid)
    for row in ans:
        print(''.join(row))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for h in range(H):
    aw = input()
    if '#' not in aw:
        continue
    a.append(aw)

skip = []
counter = 0
for i in range(W):
    if '#' not in [x[i] for x in a]:
        skip.append(i)

for row in a:
    for i in range(len(row)):
        if i not in skip:
            print(row[i], end='')
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g_list=[]
w_count=[0]*w

for i in range(h):
  a=input()
  if '#' in a:
    g_list.append(list(a))
    a_char=list(g_list[len(g_list)-1])
    for j in range(len(a_char)):
      if a_char[j] == '#':
        w_count[j] +=1

for k in range(len(w_count)):
  if w_count[len(w_count)-k-1] == 0:
    for l in range(len(g_list)):
      g_list[l].pop(len(w_count)-k-1)


for m in range(len(g_list)):
  print(''.join(g_list[m]))

Submission status: Accepted

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

lines = []
for j in A:
    for k in j:
        if "#" in k:
            lines.append(k)
lines_t = ["".join(list(i)) for i in zip(*lines)]
B = []
for g in lines_t:
    if "#" in g:
        B.append(g)
C = []
C = ["".join(list(i)) for i in zip(*B)]
for v in C:
    print(v)

Submission status: Accepted

Solution code:
import sys
h, w = map(int, sys.stdin.readline().split())
a = [input() for _ in range(h)]
ans_tmp = []
for i in range(h):
    if '#' in a[i]:
        ans_tmp.append(a[i])

not_hash_num = set()
cnt = 0
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            break
        if j == h-1:
            cnt += 1
            not_hash_num.add(i)

# print(ans_tmp)
# print(not_hash_num)
ans = [ [] for _ in range(len(ans_tmp))]
# print(ans)

for i in range(w):
    if i in not_hash_num:
        continue
    for j in range(len(ans_tmp)):
        ans[j].append(ans_tmp[j][i])

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
color = []
count = 0
for i in range(h):
    tmp = input()
    if "#" in tmp:
        count +=1
        color.append(tmp)

column_count = [0] * w
for i in range(count):
    for j in range(w):
        if color[i][j] ==".":
            column_count[j]+=1

show_index = [i for i in range(len(column_count)) if column_count[i]<count]            
for i in range(count):
    content = ""
    for j in show_index:
        content += color[i][j]
    print(content)

Submission status: Accepted

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

a = []
for i in range(H):
    tmp = input()
    if tmp != '.'*len(tmp):
        a.append(tmp)

b = ['' for i in range(len(a))]
for i in range(W):
    check = 0
    for j in range(len(a)):
        if a[j][i] == '#':
            check = 1
            break
    
    if check == 1:
        for j in range(len(a)):
            print()
            b[j] += a[j][i]


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

Submission status: Accepted

Solution code:
H,W = (int(i) for i in input().split())
li = []
for i in range(H):
    li.append(input())
gyou = [False for i in range(H)]
retsu = [False for i in range(W)]
for i in range(H):
    if '#' in list(li[i]):
        gyou[i] = True
        for j in range(W):
            if list(li[i])[j] == '#':
                retsu[j] = True
for i in range(H):
    l = []
    if gyou[i] == True:
        for j in range(W):
            if retsu[j] == True:
                l.append(list(li[i])[j])
    print(''.join(l))

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に変える
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]:#iがTrueなら
		for j in range(w):
			if col[j]:#jがTrueなら
				print(a[i][j], end = '')#出力
		print()

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int,input().split())

lst = []
for i in range(H):
    lst += [list(input())]

arr = np.array(lst)

lstH = []
for i in range(H):
    if all(arr[i,:] == '.'):
        lstH += [i]

arr = np.delete(arr, lstH, 0)

lstW = []

for j in range(W):
    if all(arr[:,j] == '.'):
        lstW += [j]

arr = np.delete(arr, lstW, 1)

for k in arr:
    for l in k:
        print(l, end = '')
    print()

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=np.array([[0 if x=='.' else 1 for x in input()] for _ in range(h)])
f=True
while(f):
    f=False
    i=0
    while(i<a.shape[0]):
        if np.sum(a[i])==0:
            f=True
            a=np.delete(a,i,0)
        i+=1
    i=0
    while(i<a.shape[1]):
        if np.sum(a[:,i])==0:
            f=True
            a=np.delete(a,i,1)
        i+=1
a=[list(x) for x in list(a)]
a=[['.' if x==0 else '#' for x in a[i]] for i in range(len(a))]
for i in range(len(a)):
    print(''.join(a[i]))

Submission status: Accepted

Solution code:
import sys

H, W = (raw_input()).split()
H = int(H)
W = int(W)

grid = []
for i in range(H):
    grid.append(raw_input())

new_grid = []
for i in range(H):
    if ('.'*W) != grid[i]:
        new_grid.append(grid[i])

for j in range(W):
    all_blanks = True
    for i in range(len(new_grid)):
        if new_grid[i][j] != '.':
            all_blanks = False
            break

    if all_blanks:
        for i in range(len(new_grid)):
            new_grid[i] = new_grid[i][:j] + 'b' + new_grid[i][j+1:]


for i in range(len(new_grid)):
    for j in range(W):
        if new_grid[i][j] != 'b':
            sys.stdout.write(new_grid[i][j])
    print

Submission status: Accepted

Solution code:
#ABC 107 B
h, w = map(int, input().split())
lines = []
for i in range(h):
    line = input()
    if "#" in line:
        lines.append(line)
lines_t = ["".join(list(i)) for i in zip(*lines)]
lines2 = []
for line in lines_t:
    if "#" in line:
        lines2.append(line)
lines = ["".join(list(i)) for i in zip(*lines2)]
for line in lines:
    print(line)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
board = []
for _ in range(h):
    row = input()
    if '#' in row:
        board.append(row)
result = [''] * len(board)
for i in range(w):
    if any(row[i] == '#' for row in board):
        result = [result[j] + board[j][i] for j in range(len(board))]
for rrow in result:
    print(rrow)

Submission status: Accepted

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

#[mat.remove(row) for row in mat[::] if ("#" not in row)]
#print(mat)

for row in mat[::]:
  if "#" not in row:
    mat.remove(row)
#print(mat)

showCol = [i for i in range(W) if "#" in [row[i] for row in mat]]
#print(showCol)

showCol = []
#for i in range(W):
#  if "#" in [row[i] for row in mat]:
#    showCol.append(i)
for i in range(W):
  for row in mat:
    if "#" in row[i]:
      showCol.append(i)
setCol = set(showCol)
#print(setCol)

print("\n".join(["".join([row[c] for c in setCol]) for row in mat]))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())

lst = []
for i in range(H):
    lst += [list(input())]

arr = np.array(lst)

lstH = []
for i in range(H):
    if all(arr[i,:] == '.'):
        lstH += [i]

arr = np.delete(arr, lstH, 0)

lstW = []
for j in range(W):
    if all(arr[:,j] == '.'):
        lstW += [j]

arr = np.delete(arr, lstW, 1)

for k in arr:
    for l in k:
        print (l, end = '')
    print ()

Submission status: Accepted

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

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

    

if __name__=='__main__':
    main()

Submission status: Accepted

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

for i in range(w):
    fl = True
    for j in range(h):
        if l[j][i]=='#':
            fl=False
    if fl:
        idw.append(i)
for i in range(h):
    if l[i].count('#')==0:
        idh.append(i)
for i in range(h):
    if i in idh:
        continue
    for j in range(w):
        if j in idw:
            continue
        print(l[i][j], end='')
    print('')

Submission status: Accepted

Solution code:
# h wの読み込み
h, w = map(int, input().split())
# 行列作成
mat = [input() for _ in range(h)]

# #が含まれていない行を削除
[mat.remove(row) for row in mat[::-1] if ("#" not in row)]
# #が含まれている列のインデックスを取得
showCol = [i for i in range(w) if "#" in [row[i] for row in mat]]

# 表示
print("\n".join(["".join([row[c] for c in showCol]) for row in mat]))

Submission status: Accepted

Solution code:
array = []
del_list = []

h,w = map(int, input().split())
for i in range(h):
  x = input()
  if "#" in x:
    y = list(x)
    array.append(y)
for i in range(w):
  for j in range(len(array)):
    if array[j][i] == "#":
      break
    else:
      if j == len(array)-1:
        del_list.append(i)
final_del_list = del_list[::-1]
for i in final_del_list:
  for j in range(len(array)):
    del array[j][i]
for i in range(len(array)):
    z = "".join(array[i])
    print(z)

Submission status: Accepted

Solution code:
import numpy as np

h, w = tuple(map(int, input().split()))
matrix = np.zeros((h, w), dtype=bool)
for i in range(h):
    row = np.array(list(input()))
    matrix[i, :] = row == "."

for i in range(h)[::-1]:
    if np.all(matrix[i, :]):
        matrix = np.delete(matrix, i, 0)

for i in range(w)[::-1]:
    if np.all(matrix[:, i]):
        matrix = np.delete(matrix, i, 1)

matrix = np.where(matrix, ".", "#")
for row in matrix:
    for e in row:
        print(e, end="")
    print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=input()
    A.append(a)
B=[]
for i in range(H):
    if A[i]!='.'*W:
        B.append(A[i])
C=[]
for k in range(W):
    c=[]
    for i in range(len(B)):
        c.append(B[i][k])
    C.append(c)

D=[]
for i in range(W):
    if C[i]!=['.']*len(B):
        D.append(C[i])
E=[]
for k in range(len(B)):
    e=[]
    for i in range(len(D)):
        e.append(D[i][k])
    E.append(e)

for h in range(len(E)):
    print(''.join(E[h]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

delete_row = []
for i in range(H):
    if '#' not in A[i, :]:
        delete_row.append(i)

delete_column = []
for j in range(W):
    if '#' not in A[:, j]:
        delete_column.append(j)

ans = np.delete(np.delete(A, delete_row, 0), delete_column, 1)

for i in range(len(ans[:, 0])):
    print(''.join(ans[i, :]))

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    h, w = intin()
    alistlist = []
    for i in range(h):
        alistlist.append(input())

    new_alistlist = []
    new_h = 0
    for alist in alistlist:
        if alist != '.' * w:
            new_alistlist.append(alist)
            new_h += 1
    alistlist = new_alistlist
    h = new_h

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

    new_alistlist = []
    for alist in alistlist:
        new_alist = ''
        for i in range(w):
            if i not in remove_wlist:
                new_alist += alist[i]
        new_alistlist.append(new_alist)
    alistlist = new_alistlist

    for alist in alistlist:
        print(alist)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def f(l,x):
  z=[]
  for i in range(x):
    if set(l[i])!=set('.'):
      z.append(l[i])
  return list(map(list, zip(*z)))
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
l=f(f(a,h),w)
for i in range(len(l)):
  print(''.join(l[i]))

Submission status: Accepted

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

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

a = [i for i in zip(*a)]
a = [i for i in a if "#" in i]

a = [i for i in zip(*a)]
a = [i for i in a if "#" in i]

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

Submission status: Accepted

Solution code:
h, w = [int(i) for i in input().split()]
a = []
d = []
h_new = 0
for i in range(h):
  b = input()
  if "#" in b:
    a.append(list(b))
    h_new += 1
for i in range(w):
  c = []
  for j in range(h_new):
    c.append(a[j][i])
  if "#" not in c:
    d.append(i)
e = ""
for i in range(h_new):
  for j in range(w):
    if j not in d:
      print(a[i][j],end="")
  print("\n")

Submission status: Accepted

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

for i in reversed(range(H)):
  if A[i]==["."]*W:
    A.pop(i)
    
for j in reversed(range(W)):
  flag=0
  for i in range(len(A)):
    if A[i][j]=="#":
      flag=1
  if flag==0:
    for i in range(len(A)):
      A[i].pop(j)

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

Submission status: Accepted

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

B=[]
D=[]

for i in range(H):
  if A[i]!="."*W:
    B.append(list(A[i]))
    
C=[["0" for j in range(len(B))] for i in range(W)]

for i in range(len(B)):
  for j in range(W):
    C[j][i]=B[i][j]

for i in range(W):
  if C[i]!=["."]*len(B):
    D.append(C[i])
   
E=[["0" for j in range(len(D))] for i in range(len(B))]

for i in range(len(D)):
  for j in range(len(B)):
    E[j][i]=D[i][j]
    
for i in range(len(B)):
  print("".join(E[i]))

Submission status: Accepted

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

row, col = [False] * H, [False] * W
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row[i] = 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())
rlist = [] #行を削除したリスト
#まずは.でできた行を削除したリストを作成
for i in range(h):
    olist = list(input()) #オリジナルリストから一行ずつ取り出す
    if olist != ['.']*w:
        rlist.append(olist)
#print(rlist)
#縦のリストを作成する
tlist = [0]*w
for j in rlist:
    for k in range(w):
        if j[k] == ('.'):
            tlist[k] += 1
#削除すべき行を判定するリスト
#print(tlist)
anslist = [[]]
for l in range(w):
    if tlist[l] == len(rlist):
        for m in rlist:
            m[l] = ''
#print(rlist)
newlist = []
for h in rlist:
    newlist.append(''.join(h))
#print(newlist)
for n in newlist:
    print(n)

Submission status: Accepted

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

a = []
for _ in range(h):
    row = list(input())
    if not all([c == '.' for c in row]):
        a.append(row)

all_whites = []
for j in range(w):
    if all([a[i][j] == '.' for i in range(len(a))]):
        all_whites.append(j)

for row in a:
    removed_row = [row[j] for j in range(w) if j not in all_whites]
    print(''.join(removed_row))

Submission status: Accepted

Solution code:
H,W=[int(a) for a in input().split(" ")]
tab=[input() for i in range(H)]
tab2=[]
for row in tab:
    if any([a!="." for a in row]):
        tab2.append(row)
tab = []
for column in zip(*tab2):
    if any([a!="." for a in column]):
        tab.append(column)
for row in zip(*tab):
    print("".join(row))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a = [list(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())
a = [input() for _ in range(H)]
a = [i for i in zip(*a) if i.count('#')]
a = ["".join(i) for i in zip(*a) if i.count('#')]
print("\n".join(a))

Submission status: Accepted

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

a = [input() for i in range(h)]

bh = [0] * h
bw = [0] * w

for i in range(h):
  for j in range(w):
    if a[i][j] == '#':
      bh[i] = 1
      bw[j] = 1
      
for i in range(h):
  if bh[i]:
    for j in range(w):
      if bw[j]:
        print(a[i][j], end='')
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input()for _ in range(h)]
b=[]
v=list(map(int,'0'*w))
for i,r in enumerate(a):
  if r=='.'*w:
    b.append(i)
  for j in range(w):
    v[j]+=r[j]=='.'
f=[j for j in range(w)if v[j]==h]
for i,r in enumerate(a):
  if i not in b:
    t=list(map(str,a[i]))
    for j in f:
      t[j]=''
    print(''.join(t))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=list(list(i for i in input()) for j in range(h))
b=list(x for x in a if '#' in x)
c=zip(*list(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())

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

WHITE = '.'
BLACK = '#'

new_a = []

for i in range(H):
    if BLACK in a[i]:
        new_a.append(a[i])

new_H = len(new_a)
new_W = len(new_a[0])
new_a2 = [[] for i in range(new_H)]

for j in range(new_W):

    has_black = False

    for i in range(new_H):
        if new_a[i][j] == BLACK:
            has_black = True

    if has_black:
        for i in range(new_H):
            new_a2[i].append(new_a[i][j])

for row in new_a2:
    for data in row:
        print(data, end='')
    print('')

Submission status: Accepted

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

data = []
for i in range(h):
    data.append([])
    for  j in range(w):
        data[i].append(data_t[i][j])
    
for i in range(h):
    contw=True
    line = ""
    for j in range(w):
        c = data[i][j]
        if c == "#":
            contw = False
            line+="#"
        elif c == ".":
            pre = True
            for k in range(h):
                if data[k][j] == "#":
                    pre = False
            if pre == True:
                for k in range(h):
                    data[k][j] = "_"
            else:
                line+="."
    if contw == False:
        print(line)

Submission status: Accepted

Solution code:
hw=list(map(int,input().split()))
h=hw[0]
w=hw[1]
a=[[] for i in range(h)]
b=[]
for i in range(h):
    a[i] = list(str(input()))
for i in range(h):
    y=True
    for j in range(w):
        if y and a[i][j]==".":
            y=True
        else:
            y=False
    if not(y):
        b.append(a[i][:])
c=[[] for i in range(len(b))]
e=[0 for i in range(len(b[0]))]
for i in range(len(b[0])):
    t=True
    for j in range(len(b)):
        if t and b[j][i]==".":
            t=True
        else:
            t=False
    e[i]=t
for i in range(len(b)):
    for j in range(len(b[0])):
        if not(e[j]):
            c[i].append(b[i][j])
for i in range(len(c)):
    print("".join(c[i]))

Submission status: Accepted

Solution code:
# zipを使用する版

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

a_reverse = list(map(list, zip(*a)))
ans = []
for tmp in a_reverse:
    if "#" in tmp:
        ans.append(tmp)

ans_list = list(map(list, zip(*ans)))

for tmp_list in ans_list:
    tmp = ""
    for tmp_val in tmp_list:
        tmp += tmp_val
    print(tmp)

Submission status: Accepted

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

w_check = [True] * W
for i in range(len(a)):
    for j in range(W):
        if a[i][j] == "#":
            w_check[j] = False

ans = [[] for i in range(len(a))]
for i in range(len(a)):
    for j in range(W):
        if not w_check[j]:
            ans[i].append(a[i][j])

for i in ans:
    output = ""
    for j in i:
        output += j
    print(output)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
t=[list(input()) for _ in range(h)]
for i in range(h):
    t[i]=[(tij=="#")*1 for tij in t[i]]
rows=[]
columns=[]
for i,ti in enumerate(t):
    if sum(ti)==0:
        rows+=[i]
for j,tj in enumerate(zip(*t)):
    if sum(tj)==0:
        columns+=[j]
nt=[]
for i,ti in enumerate(t):
    if i in rows:continue
    nti=[]
    for j,tij in enumerate(ti):
        if j in columns:continue
        nti+=["#" if tij else "."]
    print(*nti,sep="")

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
t=[list(input()) for _ in range(h)]
for i in range(h):
    t[i]=[(tij=="#")*1 for tij in t[i]]
t=np.array(t,dtype="i2")
rows=[]
columns=[]
for i in range(h):
    if np.sum(t[i])==0:
        rows+=[i]
for j in range(w):
    if np.sum(t[:,j])==0:
        columns+=[j]
t=np.delete(t,rows,0)
t=np.delete(t,columns,1)
for i in range(h-len(rows)):
    print(*["#" if tij else "." for tij in t[i]],sep="")

Submission status: Accepted

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

strs = [input() for i in range(h)]

hFlag = []
wFlag = []

for i in range(h):
    if len(strs[i]) == len(strs[i].replace('#','')):
        wFlag.append(False)
    else:
        wFlag.append(True)

for i in range(w):
    flag = False
    for j in range(h):
        if strs[j][i] == '#':
            flag = True
            break

    if flag :
        hFlag.append(True)
    else:
        hFlag.append(False)

for i in range(h):
    if wFlag[i]:
        for j in range(w):
            if hFlag[j]:
                print(strs[i][j], end='')

        print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [[s for s in input()] for i in range (H)]
sumh = 0
h = [False]*H
w = [False]*W
for i in range(H):
    for j in range(W):
         if A[i][j] == '#':
             h[i] = True
             w[j] = True

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

        print()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
H, W = map(int, input().split())
A = [[s for s in input()] for i in range(H)]

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

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

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

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
Map=[]
MAP=[]
Key=[]
cnt=0
import numpy as np

for i in range(H):
    tmp=input()
    if tmp!='.'*W:
        Map.append(tmp)
        
for i in Map:
    MAP.append(list(i))
    
for i in range(W):
    for j in range(len(MAP)):
        if MAP[j][i]=='.':
            cnt+=1
    if cnt==len(Map):
        Key.append(i)
    cnt=0

MAP=np.delete(MAP,Key,1)

for i in MAP:
    a=''.join(i)
    print(a)

Submission status: Accepted

Solution code:
import sys
H,W = map(int, input().strip().split(' '))
lines = [line.strip() for line in sys.stdin if '#' in line]
lines = [''.join(l) for l in zip(*lines)]  # transpose
lines = [line for line in lines if '#' in line]
lines = [''.join(l) for l in zip(*lines)]
for line in lines:
  print(line)