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 = (int(v) for v in input().split())
a = [input() for _ in range(h)]

my = [True for _ in range(h)]
mx = [True for _ in range(w)]

for y in range(h):
    for x in range(w):
        if a[y][x] != '.':
            break
    else:
        my[y] = False

for x in range(w):
    for y in range(h):
        if a[y][x] != '.':
            break
    else:
        mx[x] = False

s = ''
for y in range(h):
    for x in range(w):
        if my[y] and mx[x]:
            s += a[y][x]
    if my[y]:
        s += '\n'
print(s, end='')

Submission status: Accepted

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

my = [True for _ in range(h)]
mx = [True for _ in range(w)]

for y in range(h):
    for x in range(w):
        if a[y][x] != '.':
            break
    else:
        my[y] = False

for x in range(w):
    for y in range(h):
        if a[y][x] != '.':
            break
    else:
        mx[x] = False

for y in range(h):
    for x in range(w):
        if my[y] and mx[x]:
            print(a[y][x], end='')
    if my[y]:
        print()

Submission status: Accepted

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

ansW,ansH = [],[]
for hi in range(H):
    for wi in range(W):
        if A[hi][wi] == "#":
            break
    else:
        ansH.append(hi)
for wi in range(W):
    for hi in range(H):
        if A[hi][wi] == "#":
            break
    else:
        ansW.append(wi)

Ans = []
for hi in range(H):
    if hi not in ansH:
        ans = ""
        for wi in range(W):
            if wi not in ansW:
                ans += A[hi][wi]
        Ans.append(ans)

for ans in Ans:
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a = []
for i in range(H):
    ai = input()
    if len(set(ai)) == 1 and ai[0] == '.':
        continue
    else:
        a.append([ai[j] for j in range(len(ai))])
a = np.asarray(a).T
indices = []
for i in range(len(a)):
    if len(set(a[i])) == 1 and a[i][0] == '.':
        continue
    else:
        indices.append(i)
a = a[indices]
for ai in a.T:
    for aij in ai:
        print(aij, end='')
    print()

Submission status: Accepted

Solution code:
import sys;input()
for r in zip(*[c for c in zip(*[r for r in sys.stdin if'#'in r])if'#'in c]):print(*r,sep='')

Submission status: Accepted

Solution code:
import sys
input()
rows=[row for row in sys.stdin if '#' in row]
cols=[col for col in zip(*rows) if '#' in col]
for row in zip(*cols):print(*row, sep='')

Submission status: Accepted

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

# 黒がある行を抽出
hasb_row = []
for hi in range(h):
    for wj in range(w):
        if field[hi][wj] == "#":
            hasb_row.append(hi)
            break

# 黒がある列を抽出
hasb_col = []
for wj in range(w):
    for hi in range(h):
        if field[hi][wj] == "#":
            hasb_col.append(wj)
            break
        
# 再構成
f_ans = [[] for _ in range(len(hasb_row))]
for i, hi in enumerate(hasb_row):
    for j, wj in enumerate(hasb_col):
        f_ans[i].append(field[hi][wj:wj+1])
        
for hi in range(len(hasb_row)):
    print("".join(f_ans[hi]))

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    h,w = LI()
    a = [[c for c in S()] for _ in range(h)]
    b = []
    for i in range(h):
        if '#' in a[i]:
            b.append(a[i])
    c = [''] * len(b)
    for j in range(w):
        f = False
        for i in range(len(b)):
            if b[i][j] == '#':
                f = True
                break
        if f:
            for i in range(len(b)):
                c[i] += b[i][j]

    return '\n'.join(c)



print(main())

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
t = []
goodx = [0]*110
goody = [0]*110

for i in range(h):
    t.append(input())

for i in range(h):
    for j in range(w):
        if t[i][j] == "#":
            goodx[i] = 1
            goody[j] = 1

for i in range(h):
    if goodx[i]:
        for j in range(w):
            if goody[j]:
                print(t[i][j], end="")
        print()

Submission status: Accepted

Solution code:
import numpy as np

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

arr = np.zeros((H,W), dtype=np.object)

for h in range(H):
  chars = input()
  for w in range(W):
    #print(chars[w])
    arr[h, w] = chars[w]
h_replace = []
for h in range(H):
  if all([a == '.' for a in arr[h]]):
    h_replace.append( h )

w_replace = []
for w in range(W):
  if all([a == '.' for a in arr[:,w]]):
    w_replace.append( w )

arr = np.delete(arr, h_replace, axis=0)
arr = np.delete(arr, w_replace, axis=1)
[ print(''.join(ar)) for ar in arr.tolist() ]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    j=list(input())
    if '#' in j:
        a.append(j)
aa=zip(*[i for i in zip(*a) if '#' in i])
for i in aa:
    print(*i,sep='')

Submission status: Accepted

Solution code:
import numpy as np
import sys

H, W = map(int, raw_input().split())
a = []
for i in range(H):
	_a = list(raw_input())
	a.append(_a)
a = np.array(a)

row_exist = [False] * H
col_exist = [False] * W
for i in range(H):
	if '#' in a[i, :]:
		row_exist[i] = True
for i in range(W):
	if '#' in a[:, i]:
		col_exist[i] = True
for i in range(H):
	for j in range(W):
		if row_exist[i] and col_exist[j]:
			sys.stdout.write(a[i, j])
	if row_exist[i]:
		print ""

Submission status: Accepted

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

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(" "))
grid = []
h = H
for i in range(h):
    row = input()
    if row == "."*W:
        H -= 1
        continue
    grid.append(list(row))
for i in range(W):
    flag = True
    for j in range(H):
        if grid[j][i] == "#":
            flag = False
    if flag == True:
        for j in range(H):
            grid[j][i] = ""
for i in range(H):
    row = ""
    for j in range(W):
        row += grid[i][j]
    print(row)

Submission status: Accepted

Solution code:
import sys

def del_add_dot_list(a):
    del_index = []
    for i in range(len(a)):
        if all(map(lambda x: x=='.', a[i])):
            del_index.append(i)
    for i in del_index[::-1]:
        del a[i]
    return a

def spin(a):
    if len(a[0]) == 1:
        return [''.join(list(map(lambda x: x[0], a)))]
    else:
        return [''.join(list(map(lambda x: x[0], a)))] + spin(list(map(lambda x: x[1:], a)))

def main():
    sys.setrecursionlimit(10000)
    h, w = map(int, input().split())
    a = [input() for i in range(h)]
    deleted = spin(del_add_dot_list(spin(del_add_dot_list(a))))
    [print(l) for l in deleted]

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [input() for i in range(H)]
P = [0]*H; Q = [0]*W
for i in range(H):
    P[i] = all(A[i][j] == '.' for j in range(W))
for i in range(W):
    Q[i] = all(A[j][i] == '.' for j in range(H))
for i in range(H):
    if P[i]:
        continue
    r = []
    for j in range(W):
        if Q[j]:
            continue
        r.append(A[i][j])
    print(*r, sep='')

Submission status: Accepted

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

field = []
hist = [0 for w in range(W)]

def shrink():
    newField = []
    for h in range(H):
        line = []
        for w in range(W):
            if(hist[w] != H):
                line.append(field[h][w])
        newField.append(line)        
    return newField            

for h in range(H):
    line = list(input().strip())
    if(line.count(".") != len(line)):
        field.append(list(line))
        for w in range(W):
            hist[w] += 1 if field[-1][w] == "." else 0 
H = len(field)

newField = shrink()

for h in newField:
    print("".join(h))

Submission status: Accepted

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

DH = set()
DW = set()

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

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

Submission status: Accepted

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

v_list = []
reverse_list = [""]*W
h_list = []

# 1行全てが "." のとき削除する関数
def delete(h, input, output):
    for i in range(h):
        if "#" in input[i]:
            output.append(input[i])

# 転置する関数
def reverse(w, h, input, output):
    for i in range(w):
        for j in range(h):
            output[i] = output[i] + input[j][i]

delete(H, A, v_list)

reverse(W, len(v_list), v_list, reverse_list)

delete(W, reverse_list, h_list)

result_list = [""]*(len(h_list[0]))

reverse(len(h_list[0]), len(h_list), h_list, result_list)

for s in result_list:
    print(s)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [input() for _ in range(h)]
ans_w = []
ans_h = []
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      ans_h.append(i)
      break
for j in range(w):
  for i in range(h):
    if a[i][j] == "#":
      ans_w.append(j)
      break
for i in ans_h:
  print(*[a[i][j] for j in ans_w], sep="")

Submission status: Accepted

Solution code:
def rotate_clockwise(matrix):
    tmp = list(map(list, zip(*matrix)))[::-1]
    return list(''.join(row) for row in tmp)
    # 文字列のリストを入れるので文字列のリストで返す


def rotate_counterclockwise(matrix):
    tmp = list(map(lambda x: list(x[::-1]), zip(*matrix)))
    return list(''.join(row) for row in tmp)
    # 文字列のリストを入れるので文字列のリストで返す


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

row_remove_count = 0
while '.' * W in A:
    A.remove('.' * W)  # 行まるごと白なら、回数を記録して除く
    row_remove_count += 1

A = rotate_clockwise(A)  # 反時計回りに回す
while '.' * (H - row_remove_count) in A:
    A.remove('.' * (H - row_remove_count))

A = rotate_counterclockwise(A)  # 時計回りに回して元に戻す
print('\n'.join(A))

Submission status: Accepted

Solution code:
import numpy as np
H,W = map(int, input().split(" "))
a = []
for h in range(H):
    a.append(list(input()))
A = np.array(a)
A = (A=="#")
for h in range(H):
    word = ""
    for w in range(W):
        if any(A[h]) and any(A.T[w]):
             if A[h][w]:
                 word += "#"
             else:
                 word += "."
    if word :print(word)

Submission status: Accepted

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

for i in range(h):
    if s[i].count('#') != 0:
        s0.append(s[i])

s1 = [list(a) for a in s0]
# print(s1)
for i in range(len(s1[0])):
    for j in range(len(s1)):
        if s1[j][i] == '#':
            break
        elif j == len(s1) - 1:
            for k in range(len(s1)):
                s1[k][i] = 0
        else:
            continue
for r in s1:
    for c in r:
        if c != 0:
            print(c, end='')
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
mas = []
deltags = []
for x in range(H):
    try:
        temp = list(input())
    except:
        pass
    if "#" in temp:
        mas.append(temp)

for x in range(len(mas[0])):
    deltag = False
    for y in range(len(mas)):
        if mas[y][x] == "#":
            break
        if y == len(mas)-1:
            deltag = True
    deltags.append(deltag)

for x in range(len(mas)):
    for y in range(len(mas[x])):
      if deltags[y]:
        mas[x][y] = "A"

try:
    x = 0
    while True:
        while "A" in mas[x]:
            mas[x].remove("A")
        print("".join(mas[x]))
        x += 1
except:
    pass

Submission status: Accepted

Solution code:
import numpy as np

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

lines = np.asarray([list(input().replace("\n", "")) for h in range(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print("".join(outline))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[input() for i in range(H)]
tate=[0]*H
yoko=[0]*W
for i in range(W):
    for j in range(H):
        if A[j][i]=="#":
            tate[j]=1
            yoko[i]=1
ans=[]
for j in range(H):
    if tate[j]==0:
        continue
    a=''
    for i in range(W):
        if yoko[i]==0:
            continue
        a+=A[j][i]
    ans.append(a)
for a in ans:
    print(a)

Submission status: Accepted

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

H,W = map(int, input().split())
HW = []
for i in range(H):
    instr = input()
    # 残す行を選別
    if instr.find('#') != -1:
        HW.append(list(instr))
    # 残さない時は行数を-1
    else:
        H -= 1

# 残す列の情報を保持する
col = [False] * W
for i in range(H):
    for j in range(W):
        if HW[i][j] == '#':
            # 1回でも#があればその列はTrueになる
            col[j] = True

for i in range(H):
    for j in range(W):
        if col[j]:
            # 1文字ずつ出力
            print(HW[i][j], end='')
    # 行末の改行用
    print()

Submission status: Accepted

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

board = []
# 行から削除する
for i in range(h):
    if init_board[i] != ["."] * w:
        board.append(init_board[i])

# 行列を転置する
new_board = []
for i in range(w):
    add_row = []
    for j in range(len(board)):
        add_row.append(board[j][i])
    if add_row != ["."] * len(add_row):
        new_board.append(add_row)

# 最後に形を戻す
answer_board = []
for i in range(len(new_board[0])):
    add_row = []
    for j in range(len(new_board)):
        add_row.append(new_board[j][i])
    answer_board.append(add_row)

# 出力
for i in range(len(answer_board)):
    print("".join(answer_board[i]))

Submission status: Accepted

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

v_list = []
reverse_list = [""]*W
h_list = []

# 1行全てが "." のとき削除する関数
def delete(h, input, output):
    for i in range(h):
        if "#" in input[i]:
            output.append(input[i])

delete(H, A, v_list)

# 転置する関数
for i in range(W):
    for j in range(len(v_list)):
        reverse_list[i] = reverse_list[i] + v_list[j][i]


delete(W, reverse_list, h_list)

result_list = [""]*(len(h_list[0]))

# 転置する関数
for i in range(len(h_list[0])):
    for j in range(len(h_list)):
        result_list[i] = result_list[i] + h_list[j][i]

for s in result_list:
    print(s)

Submission status: Accepted

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

v_list = []
reverse_list = [""]*W
h_list = []

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

for i in range(W):
    for j in range(len(v_list)):
        reverse_list[i] = reverse_list[i] + v_list[j][i]

for i in range(W):
    if "#" in reverse_list[i]:
        h_list.append(reverse_list[i])

result_list = [""]*(len(h_list[0]))

for i in range(len(h_list[0])):
    for j in range(len(h_list)):
        result_list[i] = result_list[i] + h_list[j][i]

for s in result_list:
    print(s)

Submission status: Accepted

Solution code:
import numpy as np
h, w = list(map(int, input().split()))
a = np.array([list(input()) for i in range(h)])
a = a[:, ~np.all(a=='.', axis=0)]
a = a[~np.all(a=='.', axis=1)]
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)]
good_r = [False for _ in range(h)]
good_c = [False for _ in range(w)]

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

for i in range(h):
    if good_r[i]:
        string = ''
        for j in range(w):
            if good_c[j]:
                string += a[i][j]
        if len(string) > 0:
            print(string)

Submission status: Accepted

Solution code:
def rotated(a):
    b = []
    for i in range(len(a[0])):
        b.append("")
        for j in range(len(a)):
            b[-1] += a[j][i]
    return b

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

for i in range(H):
    ai = input()
    if "#" in ai:
        a.append(ai)

a = rotated(a)

for i in range(len(a) - 1, -1, -1):
    if "#" not in a[i]:
        a.remove(a[i])

a = rotated(a)

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

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
s = [list(input()) for i in range(h)]
s=[i for i in s if '#' in i]
count=0
while count<len(s[0]):
    check=0
    for i in s:
        if i[count]=='#':
            check=1
    if check==0:
        for i in s:
            i.pop(count)
    else:count+=1
for i in s:print(''.join(i))

Submission status: Accepted

Solution code:
H, W = map( int, input().split())
A = [ list( input()) for _ in range(H)]
Flag = True
yoko = [0]*H
tate = [0]*W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            yoko[i] = 1
            break
for j in range(W):
    for i in range(H):
        if A[i][j] == '#':
            tate[j] = 1
ANS = []
for i in range(H):
    if yoko[i] == 0:
        continue
    ans = ''
    for j in range(W):
        if tate[j] == 1:
            ans += A[i][j]
    ANS.append(ans)
for ans in ANS:
    print(ans)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
field = [input() for _ in range(H)]
hi, wi = set(), set()
for i in range(H):
    if not('#' in field[i]):
        hi.add(i)
for i in range(W):
    f = False
    for j in range(H):
        if field[j][i] == '#':
            f = True
    if not f:
        wi.add(i)
for i in range(H):
    if i in hi:
        continue
    for j in range(W):
        if j in wi:
            continue
        print(field[i][j], end="")
    print("")

Submission status: Accepted

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

import numpy as np

f = []
for i in range(h):
    f.append(list(map(lambda x: 0 if x=='.' else 1, list(input()))))
f = np.matrix(f)

for _ in range(2):
    f = f.T
    g = []
    for i in range(f.shape[0]):
        if np.sum(f[i]) > 0:
            g.append(f[i].tolist()[0])
    f = np.matrix(g)

for i in range(len(f)):
    print("".join(list(map(lambda x:str(x), np.array(f[i]).ravel().tolist()))).replace('1','#').replace('0','.'))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
tmp=[]
jg=[0 for _ in range(0,w)]
s=""
for i in range(0, h):
    s = input()
    if s != '.'*w:
        tmp.append(s)
    for j in range(0,len(s)):
        if s[j] == '#':
            jg[j] = 1
rs=[]
for i in range(0, len(tmp)):
    s=list(tmp[i])
    for k in range(0,w):
        if jg[k] == 0:
            s[k] = ''
    rs.append(s)
for _ in rs:
    print(''.join(_))

Submission status: Accepted

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

set_i = set()  
set_j = set()

for i in range(h):
    for j in range(w):
      if s[i][j] =="#":
        set_i.add(i)
        set_j.add(j)
        
for i in range(h):
  answer = ""
  if i in set_i:
    for j in range(w):
      if j in set_j:
        answer += s[i][j]
    print(answer)

Submission status: Accepted

Solution code:
import os
import sys

aa = input().strip().split()
h = int(aa[0])
w = int(aa[1])
a = [list(input().strip()) for _ in range(h)]
r = [[False for _ in range(i)] for i in [h, w]]

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

for i in range(h):
    if r[0][i]:
        for j in range(w):
            if r[1][j]:
                sys.stdout.write(a[i][j])

        sys.stdout.write(os.linesep)

Submission status: Accepted

Solution code:
h,w = (int(i) for i in input().split())
a,b = [],["" for i in range(w)]
for _ in range(h):
	s = input()
	if s.count("#")!=0:
		a.append(s)
		for i in range(w): b[i]+=s[i]
num,ans = [True for i in range(w)],["" for i in range(len(a))]
for i in range(w):
	if b[i].count("#")==0: num[i] = False
for i in range(len(a)):
	for j in range(w):
		if num[j]: ans[i]+=a[i][j]
for i in ans: print(i)

Submission status: Accepted

Solution code:
from sys import stdin                                                                                                                                                                                                                
                                                                                                                                                                                                                                     
h, w = [int(x) for x in stdin.readline().rstrip().split()]                                                                                                                                                                           
                                                                                                                                                                                                                                     
a = []                                                                                                                                                                                                                               
for _ in range(h):                                                                                                                                                                                                                   
    i = list(input())                                                                                                                                                                                                                
    if "#" in i:                                                                                                                                                                                                                     
        a.append(i)                                                                                                                                                                                                                  
ans = zip(*[x for x in zip(*a) if "#" in x])                                                                                                                                                                                         
for s in ans:                                                                                                                                                                                                                        
    print(*s, sep="")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
row=[]
for i in range(H):
    row.append(input())
i=0
while(True):
    if('.'*W in row):
        row.remove('.'*W)
    else:
        break
columns=[]
for i in range(W):
    for j in range(len(row)):
        if(j==0):
            columns.append(row[j][i])
        else:
            columns[i]+=row[j][i]
while(True):
    if('.'*(len(row)) in columns):
        columns.remove('.'*len(row))
    else:
        break
row = []
for i in range(len(columns[0])):
    for j in range(len(columns)):
        if(j==0):
            row.append(columns[j][i])
        else:
            row[i]+=columns[j][i]
for i in range(len(row)):
    print(row[i])

Submission status: Accepted

Solution code:
a, b = map(int, input().split(" "))

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

d = [False, 0]

for i in range(a):
    if d[0]:
        i -= d[1]
    if c[i] == ['.' for i in range(b)]:
        del c[i]
        d[0] = True
        d[1] += 1
a -= d[1]
c = list(map(list, zip(*c)))
d = [False, 0]

for i in range(b):
    if d[0]:
        i -= d[1]
    if c[i] == ['.' for i in range(a)]:
        del c[i]
        d[0] = True
        d[1] += 1
b -= d[1]

if len(c) == 1:
    print("#")
else:
    for i in list(map(list, zip(*c))):
        for j in range(b):
            print(i[j], end="")
        print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
X=[0 for i in range(W)]
Y=[0 for i in range(H)]
for i in range(H):
    flag=0
    for j in range(W):
        if a[i][j]=="#":
            flag=1
            break
    if flag==0:
        Y[i]=1
for j in range(W):
    flag=0
    for i in range(H):
        if a[i][j]=="#":
            flag=1
            break
    if flag==0:
        X[j]=1
for i in range(H):
    st=""
    if Y[i]==1:
        continue
    for j in range(W):
        if X[j]==0:
            st+=a[i][j]
    print(st)

Submission status: Accepted

Solution code:
import numpy as np

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

field=[i for i in field if "#" in i]

field=np.array(field)
#print(field)

field=np.rot90(field,k=1)
field=field.tolist()

field=[i for i in field if "#" in i]

field=np.rot90(field,k=-1)
field=field.tolist()

#print(field)
for i in field:
    print("".join(i))

Submission status: Accepted

Solution code:
import numpy as np
def f(s):
    s = s.replace('.', '0')
    s = s.replace('#', '1')
    lst = [int(n) for n in s]
    return np.array(lst)
h, w = list(map(int, input().split()))
a = np.array([f(input()) for i in range(h)])
b = a[:, ~np.all(a==0, axis=0)]
ans_ = b[~np.all(a==0, axis=1)]
ans = ans_.tolist()
for i in range(len(ans)):
    out3 = [str(n) for n in ans[i]]
    out2 = ''.join(out3)
    out1 = out2.replace('0', '.')
    out0 = out1.replace('1', '#')
    print(out0)

Submission status: Accepted

Solution code:
arg1, arg2 = input().split()
#arg1 = '7'

input_list = []
for i in range(int(arg1)):
    input_list.append(input())

#input_list = ['......', '....#.', '.#....', '..#...', '..#...', '......', '.#..#.']
target_list = []
for row in input_list:
    target_list.append(list(row))
#print(target_list)


# 縦が難しい
# やっぱりまず横を消してしまう。
target_list2 = []
for i in range(len(target_list)):
    for j in range(len(target_list[i])):
        if target_list[i][j] == '#':
            target_list2.append(target_list[i])
            break

#print(target_list2)

target_list3 = list(map(list, zip(*target_list2)))

#print(target_list3)

target_list4 = []
for i in range(len(target_list3)):
    for j in range(len(target_list3[i])):
        if target_list3[i][j] == '#':
            target_list4.append(target_list3[i])
            break

#print(target_list4)

ans_list = list(map(list, zip(*target_list4)))
#print(ans_list)


for row in ans_list:
    moji = ''
    for x in row:
        moji += x
    print(moji)

Submission status: Accepted

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

li=[]
for i in range(h):
    li.append(list(input()))

p=[]
count=0
for j, i in enumerate(li):
    if "#" not in i:
        p.append(j)
        h-=1
for i in p:
    temp=i-count
    del li[temp]
    count+=1


tli=[]
for i in range(w):
    temp=[]
    for j in li:
        temp.append(j[i])
    tli.append(temp)

count=0
p=[]
for k, i in enumerate(tli):
    if "#" not in i:
        p.append(k)
        w-=1
for i in p:
    temp=i-count
    del tli[temp]
    count+=1

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

Submission status: Accepted

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

def method(grid, cnt, i):
    if cnt == len(grid) - 1 and grid[cnt][i] == '.':
        w_list.append(i)
    elif cnt < len(grid) - 1 and grid[cnt][i] == '.':
        method(grid, cnt + 1, i)
    else:
        False


for i in range(h):
    n = list(input())
    if n.count('.') == len(n):
        pass
    else:
        grid.append(n)

w_list = []
cnt = 0
for i in range(w):
    # ここで最初の値が。なら、次の配列も見に行くアルゴリズムをつくる
    # [
    # [000], ここで最初は０なので、下の配列も見に行く。これを。があるだけ繰り返す
    # [010],
    # [010],
    # [010]
    # ]
    method(grid, cnt, i)

w_list.reverse()

for n in w_list:
    for i in grid:
        i.pop(n)


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