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())
a = [list(map(str, list(input()))) for i in range(h)]
l1 = ["." for i in range(w)]
l2 = ["." for i in range(h)]
for i in range(h):
  if "#" in a[i]:
    l2[i] = "#"
for i in range(w):
  if "#" in [a[j][i] for j in range(h)]:
    l1[i] = "#"
for i in range(h):
  l = []
  for j in range(w):
    if l1[j] == "#" and l2[i] == "#":
      l.append(a[i][j])
  if len(l) != 0:
    print("".join(l))

Submission status: Accepted

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

#1 1番内側の処理 [input() for i in range(h)] で1行ごとに文字列としてリストに格納
#2 [i for i in [#1] if '#' in i] で内側のリストに格納した要素で"#"を含むものを i に格納する (ここはリストの展開)
#3 [i for i in zip(#2) if "#" in i] #2で作成したリストを要素の先頭、2番目...のように
#縦で構成された要素を集めたリストに作り替える、この際"#"を含まないものは除かれる(ifの部分)
#4 [i for i in zip(#3)] を行うことによって縦横の入れ替わったリストをもう一度入れ替える(元に戻す)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a1=[[*input()] for _ in range(h)];a2=[i for i,j in enumerate(zip(*a1)) if j.count('.')==h]
[print(*[k for l,k in enumerate(j) if l not in a2],sep='') for j in [i for i in a1 if i.count('.')<w]]

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
field = []
for _ in range(H):
    tmp = input()
    if tmp.count('#') == 0:
        continue
    else:
        field.append(tmp)
ans_field = [""] * len(field)
for column in range(W):
    del_flag = True
    for row in range(len(field)):
        if field[row][column] == '#':
            del_flag = False
            break
    if not del_flag:
        for row in range(len(field)):
            ans_field[row] += field[row][column]
for val in ans_field:
    print(val)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
field = []
for _ in range(H):
    tmp = input()
    if tmp.count('#') == 0:
        continue
    else:
        field.append(tmp)
ans_field = ["."] * len(field)
for column in range(W):
    del_flag = True
    for row in range(len(field)):
        if field[row][column] == '#':
            del_flag = False
            break
    if not del_flag:
        for row in range(len(field)):
            ans_field[row] += field[row][column]
for val in ans_field:
    print(val[1:])

Submission status: Accepted

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

for i in range(h):
    g.append(list(map(lambda x: 0 if x == '.' else 1, list(input()))))

changed = True
while changed:
    changed = False
    for row in g:
        if sum(row) == 0:
            g.remove(row)
            changed = True

    t = list(zip(*g))
    for column in t:
        if sum(column) == 0:
            t.remove(column)
            changed = True

    g = list(zip(*t))

result = ["".join(list(map(lambda x: "#" if x else ".", row))) for row in g]

for row in result:
    print(row)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
a2=[k for k in a if k!=["." for j in range(w)]]
h=len(a2)
count=[True for j in range(w)]
for j in range(w):
    res=True
    for i in range(h):
        if a2[i][j]=="#":
            res=False
            break
    if res:
        count[j]=False
a3=[[a2[i][j] for j in range(w) if count[j]] for i in range(h)]
for i in range(h):
    print("".join(a3[i]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[[] for i in range(h)]
g=[]
r=[]
ans=[[] for i in range(h)]
for i in range(h):
    l[i]=list(input())
for i in range(h):
    if not all(l[i][j]=="." for j in range(w)):
        g.append(i)

for x in range(w):
    if not all(l[j][x]=="." for j in range(h)):
        
        r.append(x)
for i in g:
    for j in r:
        ans[i].append(l[i][j])
for i in g:
    print("".join(ans[i]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
M = [""]*H
r = [False]*H
c = [False]*W

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

for i in range(H):
  for j in range(W):
    if M[i][j]=="#":
      r[i]=True
      c[j]=True
      
for i in range(H):
  if r[i]:
    for j in range(W):
      if c[j]:
        print(M[i][j],end="")
    print()

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
D=[]
c=[0]*W
n=[]
for i in range(H):
  a=input()
  d=0
  for j in range(W):
    if a[j]==".":
      c[j]+=1
      d+=1
  if d!=W:
    D.append(a)
for x in range(W):
  if c[x]==H:
    n.append(x)
for y in range(len(D)):
  for z in range(W):
    if z not in n:
      print(D[y][z],end="")
  print("")

Submission status: Accepted

Solution code:
s = input().split()

h = int(s[0])
w = int(s[1])

line = []
row = []

a = [''] * h

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

for i in range(h):
    line.append(False)
for i in range(w):
    row.append(False)

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

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

Submission status: Accepted

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

vrows = {r: False for r in range(h)}
vcols = {c: False for c in range(w)}

for r in range(h):
    for c in range(w):
        if a[r][c] == '#':
            vrows[r] = True
            vcols[c] = True

for r in range(h):
    if vrows[r]:
        row = ''
        for c in range(w):
            if vcols[c]:
                row += a[r][c]
        print(row)

Submission status: Accepted

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

ahw = []
for i in range(h):
  aw = [a for a in input()]
  ahw.append(aw)

row = [False] * h
column = [False] * w
for i in range(h):
  for j in range(w):
    if ahw[i][j] == "#" :
      row[i] = True
      column[j] = True

for i in range(h):
  if row[i] :
    for j in range(w):
      if column[j]:
        print(ahw[i][j],end = "")
    print()

Submission status: Accepted

Solution code:
import numpy as np

H,W=map(int,input().split())
a=[list(map(int, list(input().replace('#','1').replace('.','0')))) for _ in range(H)]

a = np.array(a)

dellist=[]
for i in range(a.shape[0]):
  if a[i,:].sum()==0:
    dellist.append(i)
a = np.delete(a,dellist,0)
    
dellist=[]
for j in range(a.shape[1]):
  if a[:, j].sum()==0:
    dellist.append(j)
a = np.delete(a,dellist,1)

ans=[]
for i in range(a.shape[0]):
  tmp=''
  for j in range(a.shape[1]):
    if a[i][j]==1:
      tmp += '#'
    else:
      tmp += '.'
  ans.append(tmp)
  
for i in range(len(ans)):
  print(ans[i])

Submission status: Accepted

Solution code:
sus,fef = map(int,input().split())
r,c = [0]*sus,[0]*fef; 
duk,l,m = [],[],[]
for x in range(sus):
  cuc = input(); duk.append([c for c in cuc])
  r[x] = cuc.count('#')
  for j in range(fef):
    c[j] += 1 if cuc[j] == '#' else 0
for rt in range(sus):
  if not r[rt]: l.append(rt)
for gt in range(fef):
  if not c[gt]: m.append(gt)
for x in range(sus):
  if x in l: continue
  cucky = ''
  for y in range(fef):
    cucky += duk[x][y] if y not in m else ''
  print(cucky)

Submission status: Accepted

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

H = len(A)
A2 = []
for i in range(W):
    a = ''
    for j in range(H):
        a += A[j][i]
    if set(a) != set('.'):
        A2.append(a)

H = len(A2)
W = len(A2[0])
A = []
for i in range(W):
    a = ''
    for j in range(H):
        a += A2[j][i]
    A.append(a)

for a in A:
    print(a)

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:
# 初期入力 2020-0730-2150

import sys
input = sys.stdin.readline  #文字列では使わない
H,W = map(int, input().split())
a =[]
for h in range(H):
    *aa, =input().strip()
    a.append(aa)

x =["."]*W
del_h =[]
for h in range(H):
    if a[h] ==x:
        del_h.append(h)

y =["."]*H
del_w =[]
for w in range(W):
    d =[]
    for h in range(H):
        if a[h][w] ==".":
            d.append(".")
    if d ==y:
        del_w.append(w)

for i in range(H):
    if i in del_h:
        continue
    for j in range(W):
        if j in del_w:
            continue
        print(a[i][j],end="")
    print()

Submission status: Accepted

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

c = [i for i in range(W)]
for i in range(len(b)):
    for j in range(W):
        if b[i][j] == "#":
            if j in c:
                c.remove(j)
c.sort()
cnt = 0
for i in range(len(c)):
    c[i] -= cnt
    cnt += 1
for i in c:
    for j in range(len(b)):
        b[j] = b[j][:i]+b[j][i+1:]
for i in range(len(b)):
    print(b[i])

Submission status: Accepted

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

for i in range(h):
    a[i] = input()
    
row = [False] * h
cal = [False] * w

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

Submission status: Accepted

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

A=[]
for h in range(H):
    a = input()
    if '#' in a:
        A.append(list(a))

A=np.array(A).T
A_=[]
for w in range(W):
    a=A[w]
    if '#' in a:
        A_.append(a)
        
A_=np.array(A_).T
for a in A_:
    print(''.join(a))

Submission status: Accepted

Solution code:
import numpy as np
h,w = map(int, input().split())
a = []
for i in range(h):
    b = list(input())
    if b.count('.') == w:
        continue
    else:
        a.append(b)
c = np.array(a)
d = c.T
e = d.tolist()
f = []
for i in range(d.shape[0]):
    if e[i].count('.') == d.shape[1]:
        f.append(i)
f.sort(reverse = True)
for i in f:
    d = np.delete(d, i, 0)
ans = d.T.tolist()
for i in range(len(ans)):
    print(''.join(ans[i]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np

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

a = np.array([list(input()) for i in range(h)])

need_h = []
need_w = []
for i in range(h):
    tmp = a[i, :].tolist()
    if set(tmp) != set(["."]):
        need_h.append(i)

# print(a)
for i in range(w):
    tmp = a[:, i].tolist()
    if set(tmp) != set(["."]):
        need_w.append(i)
# print(need_w)

# print(need_h)
# print(need_w)
ans = np.take(np.take(a, need_h, axis=0), need_w, axis=1)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

count = 0
index = 0
while count < H:
    line = board[index]
    isWhite = True
    for i in range(len(line)):
        if line[i] == '#':
            isWhite = False
    if isWhite:
        board.pop(index)
    else:
        index += 1
    count += 1

count = 0
index = 0
while count < W:
    isWhite = True
    for i in range(len(board)):
        if board[i][index] == '#':
            isWhite = False
    if isWhite:
        for j in range(len(board)):
            board[j].pop(index)
    else:
        index += 1
    count += 1

for i in range(len(board)):
    line = board[i]
    lineString = ''
    for j in range(len(line)):
        lineString += line[j]
    print(lineString)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    h, w = map(int, readline().split())
    grid = []
    hd = 0
    for row in range(h):
        s = input()
        if all([char == "." for char in s]):
            hd += 1
        else:
            grid.append(s)

    rem = []
    for col in range(w):
        for row in range(h - hd):
            if grid[row][col] == "#":
                break
        else:
            rem.append(col)

    for row in range(h-hd):
        disp = ""
        for col in range(w):
            if col in rem:
                continue
            disp += grid[row][col]
        print(disp)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
H,W = (int(X) for X in input().split())
A = np.zeros((H,W),dtype=bool)
for TH in range(0,H):
    A[TH,:] = np.array([True if X=='.' else False for X in input()])
    Row = [TH for TH in range(0,H) if np.all(A[TH,:])==True]
for TW in range(0,W):
    Column = [TW for TW in range(0,W) if np.all(A[:,TW])==True]

A = np.delete(np.delete(A,Row,0),Column,1)
for THD in range(0,H-len(Row)):
    Disp = ['.' if X==True else '#' for X in A[THD,:]]
    print(''.join(Disp))

Submission status: Accepted

Solution code:
H,W = [int(i) for i in input().split()]
A = [list(input()) for i in range(H)]
i = 0
while i < len(A):
    if A[i].count(".") == len(A[0]):
        del A[i]
    else:
        i += 1
i = 0
while i < len(A[0]):
    if [j[i] for j in A].count(".") == len(A):
        for j in range(len(A)):
            del A[j][i]
    else:
        i += 1
print("\n".join("".join(i) for i in A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# abc107_b.py
# https://atcoder.jp/contests/abc107/tasks/abc107_b

# B - Grid Compression /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 縦 H行、横 W 列のマス目があります。 上から i 行目、左から j 列目のマスを (i,j) と表します。 
# 各マスは白または黒です。 マス目の配色は、H 行 W 列の行列 (ai,j) によって与えられます。 
# ai,j が . ならばマス (i,j) は白であり、ai,j が # ならばマス (i,j)は黒です。
# すぬけ君はこのマス目を圧縮しようとしています。 そのために、白いマスのみからなる行または列が存在する間、次の操作を繰り返し行います。

#     操作: 白いマスのみからなる行または列をひとつ任意に選び、その行または列を取り除いて空白を詰める。

# 各操作でどの行または列を選ぶかによらず、最終的なマス目は一意に定まることが示せます。 最終的なマス目を求めてください。

# 制約
#     1≤H,W≤100
#     ai,jは . または # である。
#     マス目全体で少なくともひとつは黒いマスが存在する。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# H W
# a1,1...a1,W
# :
# aH,1...aH,W

# 出力
# 最終的なマス目を、入力と同様のフォーマットで出力せよ。 ただし、行数および列数は省くこと。 詳しくはサンプルを参照せよ。

# 入力例 1
# 4 4
# ##.#
# ....
# ##.#
# .#.#

# 出力例 1
# ###
# ###
# .##

# 元のマス目における第 2行および第 3列がそれぞれ取り除かれます。

# 入力例 2
# 3 3
# #..
# .#.
# ..#

# 出力例 2
# #..
# .#.
# ..#

# 白いマスのみからなる行または列が存在しないので、操作は行われません。

# 入力例 3
# 4 5
# .....
# .....
# ..#..
# .....

# 出力例 3
# #

# 入力例 4
# 7 6
# ......
# ....#.
# .#....
# ..#...
# ..#...
# ......
# .#..#.

# 出力例 4
# ..#
# #..
# .#.
# .#.
# #.#


def calculation(lines):
    N, W = list(map(int, lines[0].split()))
    masus = list()
    for i in range(N):
        line = lines[i+1]
        if line != '.'*W:
            masus.append(line)
    for w in range(W):
        flag = True
        for masu in masus:
            if masu[w] == '#':
                flag = False
        if flag:
            for i in range(len(masus)):
                masus[i] = masus[i][:w] + ' ' + masus[i][w+1:]
    for i in range(len(masus)):
        masus[i] = masus[i].replace(' ', '')
    return masus


# 引数を取得
def get_input_lines():
    line = input()
    H, W = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(H):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4 4', '##.#', '....', '##.#', '.#.#']
        lines_export = ['###', '###', '.##']
    if pattern == 2:
        lines_input = ['3 3', '#..', '.#.', '..#']
        lines_export = ['#..', '.#.', '..#']
    if pattern == 3:
        lines_input = ['4 5', '.....', '.....', '..#..', '.....']
        lines_export = ['#']
    if pattern == 4:
        lines_input = ['7 6', '......', '....#.', '.#....', '..#...', '..#...', '......', '.#..#.']
        lines_export = ['..#', '#..', '.#.', '.#.', '#.#']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	w,h = map(int,input().split())
	
	A = []
	for _ in range(w):
		cmd = input()
		if cmd.count(".") != len(cmd):
			A.append(cmd)

	B = []
	for i in range(h):
		st = ""
		for a in A:
			st += a[i]
		if st.count(".") != len(st):
			B.append(st)

	#元に戻す
	C = []
	w = len(B[0])
	for j in range(w):
		st = ""
		for b in B:
			st += b[j]
		C.append(st)

	for c in C:
		print(c)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
g=[input() for _ in range(h)]
a=['' for _ in range(h)]
for y in range(w):
  if any(s[y]=='#' for s in g):
    for x in range(h):
      a[x]+=g[x][y]
for s in a:
  if s.count('#'): print(s)

Submission status: Accepted

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

for _ in range(w):
    for i, j in enumerate(a):
        if set(j) == set("."):
            a.pop(i)
    a_t = [list(x) for x in zip(*a)]
    for i, j in enumerate(a_t):
        if set(j) == set("."):
            a_t.pop(i)
    a = [list(x) for x in zip(*a_t)]

[print(*ans, sep="") for ans in a]

Submission status: Accepted

Solution code:
MM = input().split()
A = int(MM[0])
B = int(MM[1])
list1 =[]
for i in range(A):
  aa = input()
  if '.'*B == aa:
    pass
  else:
    list1.append(list(aa))


for i in range(B):
  count = 0
  for j in range(len(list1)):
    if list1[j][i] == '#':
      count +=1
  if count == 0:
    for j in range(len(list1)):
     
      list1[j][i] = 'a'

for i in list1:
  if 'a' in i:
    i.remove('a')

for i in list1:
  for j in i:
    if j != 'a':
      print(j,end='')
  print()

Submission status: Accepted

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

w_row = ['.' for i in range(w)]
del_row_list = []
del_col_list = []

for i in range(h):
    if field[i] == w_row:
        del_row_list.append(i)

for j in range(w):
    count = 0
    for i in range(h):
        if field[i][j] == '.':
            count += 1
    if count == h:
        del_col_list.append(j)

for i in range(h):
    if i in del_row_list:
        continue
    for j in range(w):
        if j in del_col_list:
            continue
        print(field[i][j], end='')
    print('')

Submission status: Accepted

Solution code:
import copy
H,W=map(int,input().split())
List = []
for i in range (H):
  List.append(list(input()))
flag = False
NewList = []
#横の列の確認
for i in range(H):
  for j in range(W):
    if List[i][j]== "#":
      flag = True
  if flag:
    NewList.append(List[i])
  flag = False
flag1 = [True]*W
#縦の列の確認
for i in range(W):
  for j in range(len(NewList)):
    if NewList[j][i]== "#":
      flag1[i] = False
      
for j in range(len(NewList)):
  for i in range(W-1,-1,-1):
    if flag1[i]:
      NewList[j].pop(i)    
  
resList=[""]*H
for i in range(len(NewList)):
  for j in range(len(NewList[i])):
    resList[i] += NewList[i][j]
for element in resList:
  print(element)

Submission status: Accepted

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

next_data = []
# 横列処理
for d in data:
    if "#" in d:
        next_data.append( d )

next_next_data = []
origin_v_data = []
# 縦列処理
for i in range( len(next_data[0]) ):
    # 縦配列生成
    v_data = []
    for j in range( len(next_data) ):
        v_data.append( next_data[j][i] )

    # 配列チェック
    if "#" in v_data:
        origin_v_data.append( v_data )

ans_data = []
for i in range( len(origin_v_data[0]) ):
    join_data = []
    for j in range( len(origin_v_data) ):
        join_data.append( origin_v_data[j][i] )
    ans_data.append( join_data )

# 標準出力
for a in ans_data:
    print("".join(a))

Submission status: Accepted

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

# 行から見る
row = []
column = []
for i in range(h):
    if not masu[i] == ['.'] * w:
        row.append(i)

column = []
for i in range(w):
    flg = 0
    for j in range(h):
        if masu[j][i] == '#':
            flg = 1
    if flg == 1:
        column.append(i)

for i in row:
    for j in column:
        print(masu[i][j],end='')
    print()

Submission status: Accepted

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

# 行から見る
row = []
column = []
for i in range(h):
    if not masu[i] == ['.'] * w:
        row.append(i)

column = []
for i in range(w):
    flg = 0
    for j in range(h):
        if masu[j][i] == '#':
            flg = 1
    if flg == 1:
        column.append(i)

for i in row:
    l = masu[i]
    for j in column:
        print(masu[i][j],end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in range(h):
    x = input()
    if "#" in x:
        a.append(x)
    else:
        h -= 1
for i in range(w - 1, -1, -1):
    for j in range(h):
        if a[j][i] == "#":
            break
    else:
        for k in range(h):
            a[k] = a[k][:i] + a[k][i + 1 :]
print(*a, sep="\n")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
sh=set()
sw=set()
for i in range(h):
    ok=True
    for j in range(w):
        if a[i][j]=="#":
            ok=False
    if ok:
        sh.add(i)
for j in range(w):
    ok=True
    for i in range(h):
        if a[i][j]=="#":
            ok=False
    if ok:
        sw.add(j)
#print(sh)
#print(sw)
ans=[]
for i in range(h):
    l=""
    if i in sh:
        continue
    for j in range(w):
        if j in sw:
            continue
        l+=a[i][j]
    ans.append(l)
for c in ans:
    print(c)

Submission status: Accepted

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

dlist = []
nuse = [0]*w

for i in range(h):
    if not "#" in field[i]:
        dlist.append(i)
    for j in range(w):
        if field[i][j] == "#":
            nuse[j] += 1

nuse = [True if w > 0 else False for w in nuse]
for i in range(h):
    if i in dlist:
        continue
    s = list(itertools.compress(field[i], nuse))
    print("".join(s))

Submission status: Accepted

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

for _ in range(H):
  x = input()
  if x != "."*W:
    grid.append(x)

h = len(grid)
Flag = [True]*W

for j in range(W):
  if all(grid[i][j] == "." for i in range(h)):
    Flag[j] = False

for i in range(h):
  print("".join([grid[i][j] for j in range(W) if Flag[j]]))

Submission status: Accepted

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

for _ in range(H):
  x = input()
  if x != "."*W:
    grid.append(x)

h = len(grid)
Flag = [True]*W

for j in range(W):
  if all([grid[i][j] == "." for i in range(h)]):
    Flag[j] = False

for i in range(h):
  print("".join([grid[i][j] for j in range(W) if Flag[j]]))

Submission status: Accepted

Solution code:
import numpy as np
H,W = map(int,input().split())
grid = []
for i in range(H):
    mojiretsu = input()
    moji = []
    for k in range(len(mojiretsu)):
        moji.append(mojiretsu[k])
    grid.append(moji)
grid = np.array(grid)
flug1 = True
flug2 = True
flug3 = False
flug4 = False
while flug1:
    for i in range(grid.shape[0]):
        if np.all(grid[i,:] == "."):
            grid = np.delete(grid, i, 0)
            flug3 = False
            break
        else:
            flug3 = True
    if flug3 == True:
        flug1 = False
while flug2:
    for j in range(grid.shape[1]):
        if np.all(grid[:,j] == "."):
            grid = np.delete(grid, j, 1)
            flug4 = False
            break
        else:
            flug4 = True
    if flug4 == True:
        flug2 = False
for height in range(grid.shape[0]):
    print("".join(list(grid[height,:])))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-26 20:42:26 +0900
# LastModified: 2020-07-20 04:38:38 +0900
#


import os
import sys
import numpy as np
# import pandas as pd


def main():
    h, w = map(int, input().split())
    a = np.zeros((h,w), dtype = np.int32)
    for i in range(h):
        s = input()
        for j in range(w):
            if s[j] == '.':
                a[i, j] = 1
    stack = []
    delete_colums = 0
    delete_index = 0
    for i in range(h):
        if np.sum(a[i, :]) == w:
            stack.append(i)
            delete_index += 1
    while stack:
        p = stack.pop()
        a = np.delete(a, obj=p, axis=0)

    for i in range(w):
        if np.sum(a[:, i]) == h-delete_index:
            stack.append(i)
            delete_colums += 1
    while stack:
        p = stack.pop()
        a = np.delete(a, obj=p, axis=1)
    
    for i in range(h-delete_index):
        for j in range(w-delete_colums):
            if a[i, j] == 0:
                print('#', end='')
            else:
                print('.', end='')
        print()
            



if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(H):
    if A[i] == ['.'] * W:
        A[i] = ['-1'] * W
for j in range(W):
    count = 0
    for i in range(H):
        if A[i][j] == '#':
            break
        count += 1
    if count == H:
        for i in range(H):
            A[i][j] = '-1'
for a in A:
    if a == ['-1'] * W:
        continue
    ans = [ai for ai in a if not ai == '-1']
    print(''.join(ans))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())
# 行方向の除去…入力時に省く
# 列方向の除去…フラグを用意して、#が含まれている列のフラグを立てる
# 最終的にフラグが立っている列のみ出力
grid = []
black = [0] * W
for i in range(H):
    a = readline().decode().rstrip()
    if a.count('#') != 0:
        grid.append(a)
        for j in range(W):
            if a[j] == '#':
                black[j] = 1

# フラグが立っている列のみ文字列を結合していき、出力
for a in grid:
    s = ''
    for j in range(W):
        if black[j] == 1:
            s += a[j]
    print(s)

Submission status: Accepted

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

# 横方向を調べる
for i in reversed(range(H)):
        if a[i].count(".") == W:
            a.pop(i)

# 抜けた分、縦の長さを再定義する
H = len(a)

# 縦方向を調べる
for i in reversed(range(W)):
    for j in range(H):
        if a[j][i] == ".":
            pass
        else:
            break
    else:
        for j in range(H):
            a[j].pop(i)

# 出力
for i in range(H):
    a[i] = "".join(a[i])
    print(a[i])

Submission status: Accepted

Solution code:
# B - Grid Compression
H, W = map(int, input().split())
grid = []

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

ans = [''] * len(grid)

for i in range(W):
	count = 0
	
	for j in range(len(grid)):
		if grid[j][i] == '#':
			count += 1
	
	if count > 0:
		for j in range(len(grid)):
			ans[j] += grid[j][i]

for a in ans:
	print(a)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
for i in range(h):
    b = input()
    if len(set(b)) > 1 or b[0] == '#':
        a.append(b)
c = list(range(w))
for i in range(w):
    f = 0
    for j in range(len(a)):
        if a[j][i] == '#':
            f = 1
            break
    if f == 0:
        c.remove(i)

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