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())
e = []
for i in range(h):
    e.append(list(input()))
rey = [0 for i in range(h)]
rex = [0 for i in range(w)]
for i in range(h):
    count = 0
    for j in range(w):
        if e[i][j] == ".":
            count += 1
    if count == w:
        rey[i] = 1

for i in range(w):
    count = 0
    for j in range(h):
        if e[j][i] == ".":
            count += 1
    if count == h:
        rex[i] = 1

for i in range(h):
    if rey[i]:
        continue
    else:
        for j in range(w):
            if rex[j]:
                continue
            else:
                print(e[i][j],end="")
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
ans=[]
for i in range(h):
    x=input()
    if x!='.'*w:
        ans.append(x)
if len(ans)==0:
    print(*ans)
    exit()
flag=[0 for _ in range(w)]
for i in range(w):
    if ans[0][i]=='.':
        flag[i]=1
if len(ans)==1:
    for i in range(w):
        if flag[i]==0:
            print(ans[0][i],end='')
else:
    for i in range(1,len(ans)):
        for j in range(w):
            if flag[j]==1:
                if ans[i][j]!='.':
                    flag[j]=0
    for i in range(len(ans)):
        for j in range(w):
            if flag[j]==0:
                print(ans[i][j],end='')
        print()

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if M[i][j]=='#':
            tate[i]=True
            yoko[j]=True

for i in range(H):
    if tate[i]:
        out = ''
        for j in range(W):
            if yoko[j]:
                out = out + M[i][j]
        print(out)

Submission status: Accepted

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

has_black_rows = [False for _ in range(h)]
has_black_columns = [False for _ in range(w)]

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

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(input())
H=[]
W=[]
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            H.append(i)
            W.append(j)
H=set(H)
W=set(W)
for j in H:
    ans=[]
    for i in W:
        ans.append(a[j][i])
    print("".join(ans))

Submission status: Accepted

Solution code:
h, w=map(int, input().split())
a=[input() for _ in range(h)]
s=set()
t=set()
for i in range(h):
  if '#' in a[i]:
    s.add(i)
    for j in range(w):
      if a[i][j]=='#':
        t.add(j)
for i in s:
  l=''
  for j in t:
    l+=a[i][j]
  print(l)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
lis = [list(input()) for _ in range(h)]
cnt = 0
for i in reversed(range(h)):
    if set(lis[i])=={'.'}:
        lis.pop(i)
        cnt += 1
for j in reversed(range(w)):
    if set([l[j] for l in lis])=={'.'}:
        for k in range(h-cnt):
            lis[k].pop(j)
for m in lis:
    print("".join(m))

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

H,W = inputIL()
data = []
for _ in range(H):
  s = inputS()
  if s != "."*W:
    data.append(s)

memo = []
for i in range(W):
  flag = 1
  for j in range(len(data)):
    if data[j][i] == "#":
      flag = 0
  if flag == 0:
    memo.append(i)
    
ans = [[data[j][i] for i in memo] for j in range(len(data))]

for i in range(len(ans)):
  print(*ans[i],sep="")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
grid = [[True]*W for _ in range(H)]
for i in range(H):
    flag = True
    for j in range(W):
        if a[i][j] == '#':
            flag = False
    if flag:
        for k in range(W):
            grid[i][k] = False

for i in range(W):
    flag = True
    for j in range(H):
        if a[j][i] == '#':
            flag = False
    if flag:
        for k in range(H):
            grid[k][i] = False  

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

lall = list()
for i in range(h):
    l = list(input())
    if l != ["."] * w:
        lall.append(l)

for i in range(w):
    j = 0
    while j < len(lall) and i < len(lall[j]) and lall[j][i] == ".":
        j += 1
        if j == len(lall):
            for k in range(len(lall)):
                lall[k][i] = "0"
            break    

for i in range(len(lall)):
    print(''.join([j for j in lall[i] if j != "0"]))

Submission status: Accepted

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

del_H = []
del_W = []
for i in range(H):
  for j in range(W):
    if a[i][j] == '#':
      break
    if j == W - 1:
      del_H.append(i)
for j in range(W):
  for i in range(H):
    if a[i][j] == '#':
      break
    if i == H - 1:
      del_W.append(j)
for i in range(H):
  if i not in del_H:
    for j in range(W):
      if j not in del_W:
        print(a[i][j], end="")
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a =[]
for i in range(h):
    row = list(input())
    if '#' in row:
        a.append(row)
    else:
        h -= 1
num = []
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            num.append(i)
            break
    
for i in range(h):
    for j in num:
        print(a[i][j],end = '')
    print()

Submission status: Accepted

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

gyo = [False]*h
retsu = [False]*w
for i in range(h):
  for j in range(w):
    if a_list[i][j] == '#':
      gyo[i] = True
      retsu[j] = True
for k in range(h):
  if gyo[k]:
    for l in range(w):
      if retsu[l]:
        print(a_list[k][l], end='')
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
memo_yoko = []
memo_tate = []
for i in range(h):
    if "#" in a[i]:
        memo_yoko.append(i)

for j in range(w):
    if any(a[i][j] == "#" for i in range(h)):
        memo_tate.append(j)
#print(memo_yoko)
#rint(memo_tate)
for i in memo_yoko:
    for j in memo_tate:
        print(a[i][j], end="")
    print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
ha = 0
for i in reversed(range(h)):
    if set(a[i])=={"."}:
        a.pop(i)
        ha+=1
for i in reversed(range(w)):
    if set([s[i] for s in a])=={"."}:
        for j in range(h-ha):
            a[j].pop(i)
for ai in a:
    print("".join(ai))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
row=[]
col=[]
for i in range(h):
    if "#" in a[i][:]:
        row.append(i)
b=[list(x) for x in zip(*a)]
for j in range(w):
    if "#" in b[:][j]:
        col.append(j)
for i in row:
    for j in col:
        print(a[i][j],end="")
    print("")

Submission status: Accepted

Solution code:
import numpy as np

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

b = []
for i in a:
    if set(i) != {'.'}:
        b.append(i)
b = np.array(b)
b = b.T

c = []
for i in b:
    if set(i) != {'.'}:
        c.append(i)
c = np.array(c)
c = c.T

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

h,w=map(int, input().split())
m = [list(input().rstrip()) for i in range(h)]
ok_w=[True for i in range(h)]
ok_h=[True for i in range(w)]
#print(m)
for i in range(h):
    for j in range(w):
        #print(m[i][j])
        if "#" == m[i][j]:
           ok_w[i]=False
           ok_h[j]=False
#print(ok_h,ok_w)
for i in range(h):
    for j in range(w):
        if not ok_w[i] and not ok_h[j]:
            print(m[i][j],end="")
    print("\n",end="")

Submission status: Accepted

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

hlist, wlist = [], []
for i in range(h):
    if '#' in a[i]:
        hlist.append(i)
for j in range(w):
    if any(a[i][j] == '#' for i in range(h)):
        wlist.append(j)

for i in hlist:
    print(*[a[i][j] for j in wlist] ,sep='')

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

h, w = Is()
A = LSR(h)
H = list(all(x == '.' for x in A[i]) for i in range(h))
W = list(all(x[j] == '.' for x in A) for j in range(w))
for i in range(h):
    if H[i]:
        continue
    for j in range(w):
        if W[j]:
            continue
        print(A[i][j], end='')
    print()

Submission status: Accepted

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

A = []
for i in range(h):
    a = list(input())
    if '#' in a:
        A.append(a)
        
for i in range(w - 1, -1, -1):
    for j in range(len(A)):
        if A[j][i] == '#':
            break
    else:
        for k in range(len(A)):
            del A[k][i]
            
for a in A:
    print(''.join(a))

Submission status: Accepted

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

a = []

# 必要な行だけ読み込む
for i in range(H):
    tmp = list(input())
    if "#" not in tmp:
        continue
    else:
        a.append(tmp)

# 転置して削って転置
a = list(zip(*a))
a = [x for x in a if "#" in x]
a = list(zip(*a))

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

Submission status: Accepted

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

for h in range(H):
    a=list(input())
    A.append(a)

A=np.array(A)
hs=[]
ws=[]

for i in range(H):
    if (A[i,:]=="#").sum()==0:
        hs.append(i)
for i in range(W):
    if (A[:,i]=="#").sum()==0:
        ws.append(i)

for h in range(H):
    if h not in hs:
        L=[]
        for w in range(W):
            if w not in ws:
                L.append(A[h,w])
        print("".join(L))

Submission status: Accepted

Solution code:
# ABC107
# B
# Grid Compression

h, w = map(int, input().split())
a_list = []
for i in range(h):
    _tmp = input()
    if set(_tmp).issuperset({"#"}):
        a_list.append(_tmp)

a_list_T = [list(x) for x in zip(*a_list)]
tmp_list = []

for i in range(w):
    _tmp = a_list_T[i]
    if set(_tmp).issuperset({"#"}):
        tmp_list.append(_tmp)
        
ans = [list(x) for x in zip(*tmp_list)]

for _l in ans:
  print(*_l,sep="")

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]
delh, delw = [], []
for i in range(H):
    if all([True if i == '.' else False for i in A[i]]):
        delh.append(i)
B = [list(x) for x in zip(*A)]
for i in range(W):
    if all([True if i == '.' else False for i in B[i]]):
        delw.append(i)
B = [b for i, b in enumerate(B) if i not in delw]
A = [list(x) for x in zip(*B)]
A = [a for i, a in enumerate(A) if i not in delh]
[print(''.join(a)) for a in A]

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int,input().split())
grid = np.array([list(input()) for _ in range(h)], dtype="U1") # ここ最大の学びだ

row = []
col = []

for i in range(h):
    if (grid[i] != ".").any():
        row.append(i)

trans_grid = np.transpose(grid)

for i in range(w):
    if (trans_grid[i] != ".").any():
        col.append(i)

G = grid[row][:,col] # ここも学び。colに指定されているとこだけだす　https://qiita.com/supersaiakujin/items/d63c73bb7b5aac43898a

for g in G:
    print("".join(g))

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    H, W = readnums()
    a = [list(readstr()) for _ in range(H)]
    p = list()
    for i, aa in enumerate(a):
        if all([x == '.' for x in aa]):
            p.append(i)

    for i in reversed(p):
        a.pop(i)

    p = list()
    for i in range(W):
        c = [x[i] for x in a]
        if all([x == '.' for x in c]):
            p.append(i)

    for i in reversed(p):
        for aa in a:
            aa.pop(i)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [input() for _ in range(h)]
L = [1] * w
for i in range(w):
    if a[0][i] == '.':
        for j in range(h):
            if a[j][i] == '#':
                break
        else:
            L[i] = 0
for k in range(h):
    if '#' in a[k]:
        L2 = []
        for l in range(w):
            if L[l] == 1:
                L2.append(a[k][l])
        print(*L2, sep='')

Submission status: Accepted

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

    cond_r = [True] * H
    cond_c = [True] * W
    for r in range(H):
        if all(x == '.' for x in G[r]):
            cond_r[r] = False
    for c in range(W):
        if all(x == '.' for r in range(H) for x in G[r][c]):
            cond_c[c] = False
    for r, row in enumerate(G):
        if not cond_r[r]: continue
        for c, cell in enumerate(row):
            if not cond_c[c]: continue
            print(cell, end='')
        print()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    h, w = map(int, input().split())
    ary = [list(input()) for _ in range(h)]
    for i in reversed(range(h)):
        if len(ary[i]) == ary[i].count('.'):
            del ary[i]
    for i in reversed(range(w)):
        ok = True
        for a in ary:
            if a[i] != '.':
                ok = False
        if ok:
            for j in range(len(ary)):
                del ary[j][i]
    for a in ary:
        print("".join(a))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

a = []
for i in range(H):
    a.append(list(map(int, input().replace("#","1").replace(".","0"))))

a = np.array(a)

d1 = (np.sum(a, axis=1) == 0)
d2 = (np.sum(a, axis=0) == 0)

ret = []

for i in range(H):
    tmp = ""
    if d1[i]:
        continue
    for j in range(W):
        if d2[j]:
            continue
        tmp = tmp + str(a[i,j])
    ret.append(tmp.replace("1","#").replace("0","."))
        

print(*ret,sep="\n")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
A = [[0]*W for i in range(H)]
B = []
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            A[i][j] += 1
    if sum(A[i]) > 0:
        B.append(A[i])

ans = [[] for i in range(len(B))]
for y in zip(*B):
    if sum(y) > 0:
        for i, x in enumerate(y):
            if x:
                ans[i].append('#')
            else:
                ans[i].append('.')
for x in ans:
    print(''.join(x))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
res=[]
for i in range(h):
    if "#" not in a[i]:
      res.append(i)

resh=[]
h=len(a)
for i in range(w):
    for j in range(len(a)):
      if a[j][i]=="#":
        break
    else:
      resh.append(i)
for i in range(h):
  for j in range(w):
    if i not in res and j not in resh:
      print(a[i][j],end="")
  if i not in res:
    print("")

Submission status: Accepted

Solution code:
# coding: utf-8

h, w = map(int,input().split())
A = []

for i in range(h):
    l = list(input())
    if list(set(l)) == ['.']:
        h -= 1
    else:
        A.append(l)
#for a in A:
    #print(a)
Ans = []
for i in range(w):
    cnt = 0
    for j in range(h):
        if A[j][i] == '.':
            cnt += 1
    if cnt == h:
        Ans.append(i)

for i in Ans:
    for j in range(h):
        A[j][i] = ''

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

Submission status: Accepted

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

l = []
for i, v in enumerate(a):
    if "#" not in v:
        l.append(i)
for i in l[::-1]:
    a.pop(i)

a = list(zip(*a))
l = []
for i, v in enumerate(a):
    if "#" not in v:
        l.append(i)
for i in l[::-1]:
    a.pop(i)

a = list(zip(*a))
for i in a:
    print("".join(i))

Submission status: Accepted

Solution code:
import numpy as np
 
H,W = map(int,input().split())
MAP = []
for _ in range(H):
    tmp = tuple(input())
    MAP.append(tmp)
 
MAP = np.array(MAP)
L = []
for i in range(H):
    if all(MAP[i,:] == '.'):
        L.append(i)
 
MAP = np.delete(MAP,L,0)
L = []
for i in range(W):
    if all(MAP[:,i] == '.'):
        L.append(i)
 
MAP = np.delete(MAP,L,1)
for m in MAP:
    print(''.join(m))

Submission status: Accepted

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

A = [str(input()) for _ in range(H)]

LH = set([])
LW = set([])

for i in range(H):
  for j in range(W):
    if A[i][j] == "#":
      LH.add(i)
      LW.add(j)

UH = len(LH)
ans = []
for i in LH:
  temp = ""
  for j in LW:
    #print(i,j,A[i][j])
    temp += A[i][j]
  ans.append(temp)
print(*ans, sep="\n")

Submission status: Accepted

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

for h in range(H):
    cnt = sum([0 if i=='.' else 1 for i in grid[h]])
    if cnt==0:
        grid[h] = [0]*W

for w in range(W):
    cnt = sum([0 if grid[h][w] in ('.', 0) else 1 for h in range(H)])
    if cnt == 0:
        for h in range(H):
            grid[h][w] = 0

for g in grid:
    string = [s for s in g if not s==0]
    if len(string)==0:
        continue
    print(''.join(string))

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
l=[]
for i in range(h):
    a=list(input())
    if a[0]!="." or len(list(set(a)))!=1:
        l.append(a)

i=0
while i<len(l[0]):
    ch=True
    for k in range(len(l)):

        if l[k][i]=="#":
            ch=False
    if ch:
        for k in range(len(l)):
            del l[k][i]
        i-=1
    i+=1
for i in range(len(l)):
    print(*l[i],sep="")

Submission status: Accepted

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

yoko = [1 for i in range(h)]
tate = [1 for i in range(w)]

for i in range(h):
    if a[i].count(".") == w:
        yoko[i] = 0

a_t = [list(x) for x in zip(*a)]

for i in range(w):
    if a_t[i].count(".") == h:
        tate[i] = 0

for i in range(h):
    s = ""
    for j in range(w):
        if yoko[i] and tate[j]:
            s += a[i][j]
    if s:
        print(s)

Submission status: Accepted

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

l=[]
for i in range(H):
  x=input()
  # 白いマスのみからなる場合は追加しない
  if x!='.'*W:
    l.append(x)

rm=[]
for i in range(W):
  # フラグ
  f=True
  for j in range(len(l)):
    if l[j][i]=='#':
      f=False

  # 取り除く列の添字を保存しておく
  if f:
    rm.append(i)

a=[]
for x in l:
  for i in rm[::-1]:
    x=x[:i]+x[i+1:]
  a.append(''.join(x))

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                res.append(A[h])
                break

    res2 = [[] for _ in range(len(res))]
    for w in range(W):
        for h in range(len(res)):
            if res[h][w] == "#":
                for k in range(len(res)):
                    res2[k].append(res[k][w])
                break

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

yoko = []
tate = []

for i in range(H):
  if a[i] != "."*W:
    yoko.append(i)
for i in range(W):
  c = 0
  for j in range(H):
    if a[j][i] == "#":
      c = 1
  if c == 1:
    tate.append(i)

for y in yoko:
  s = ""
  for t in tate:
    s += a[y][t]
  print(s)

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
A = list(zip(*a))
skip_h = [] 
skip_w = []
for i in range(h):
  if a[i] == ["."] * w: skip_h.append(i)
for i in range(w):
  if A[i] == tuple(".") * h: skip_w.append(i)

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in range(h):
    a.append(input())
row = []
col = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            break
    else:
        row.append(i)
for i in range(w):
    for j in range(h):
        if a[j][i]=='#':
            break
    else:
        col.append(i)
a = [[e for j, e in enumerate(r) if j not in col] for i, r in enumerate(a) if i not in row]    
for r in a:
    print(''.join(r))

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
grid = np.array([list(input()) for _ in range(H)], dtype="U1")

row = []
col = []
for i in range(H):
    if (grid[i] != ".").any():
        row.append(i)

trans_grid = np.transpose(grid)
for i in range(W):
    if (trans_grid[i] != ".").any():
        col.append(i)


G = grid[row][:, col]
for g in G:
    print("".join(g))

Submission status: Accepted

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

hl = []
wl = []
for h in range(H):
    if sum([0 if i == "." else 1 for i in A[h]]) > 0:
        hl.append(h)

for w in range(W):
    if sum([0 if A[i][w] == "." else 1 for i in range(H)]) > 0:
        wl.append(w)

for h in hl:
    line = []
    for w in wl:
        line.append(A[h][w])
    print(*line, sep="")

Submission status: Accepted

Solution code:
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    ban_h = set()
    for h in range(H):
        if all(s == "." for s in A[h]):
            ban_h.add(h)
    ban_w = set()
    for w in range(W):
        if all("." == A[i][w] for i in range(H)):
            ban_w.add(w)

    for h in range(H):
        if h in ban_h:
            continue
        for w in range(W):
            if w in ban_w:
                continue
            print(A[h][w], end="")
        print()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

kari = []
for i in a:
    if "#" not in i:
        H -= 1
        continue
    kari.append(i)

ans = ["" for _ in range(H)]
for i in range(W):
    for j in range(H):
        if kari[j][i] == "#":
            for k in range(H):
                ans[k] += kari[k][i]
            break

for i in ans:
    print(i)

Submission status: Accepted

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


H_flag = [False]*H
W_flag = [False]*W


_map = []
for i in range(H):
    x = list(input())
    _map.append(x)
    for j in range(W):
        if x[j] == '#':
            H_flag[i] = True

for i in range(W):
    for j in range(H):
        if _map[j][i] == '#':
            W_flag[i]= True

for i in range(H):
    for j in range(W):
        if H_flag[i] and W_flag[j]:
            print(_map[i][j],end="")
    if H_flag[i] :
        print()

#print(H_flag)
#print(W_flag)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc107


def main():
    H, W = map(int, input().split())
    a = [None] * H
    for i in range(H):
        a[i] = input()

    b = []
    for i in range(H):
        if any([x == "#" for x in a[i]]):
            b.append(a[i])
    
    idx = []
    for j in range(W):
        if any([b[i][j] == "#" for i in range(len(b))]):
            idx.append(j)

    for i in range(len(b)):
        for j in range(W):
            if j in idx:
                print(b[i][j], end="")
        print()


main()
# print(main())

Submission status: Accepted

Solution code:
H,W = [int(hoge) for hoge in input().split()]
A = [input() for j in range(H)]
Row = [r for r in range(H) if all([m=="." for m in A[r]]) ]
Col = [c for c in range(W) if all([A[r][c]=="." for r in range(H)])]
print(*["".join([A[h][w]for w in range(W) if w not in Col]) for h in range(H) if h not in Row],sep="\n")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
ma = [list(str(input())) for _ in range(h)]
row = [0] * h
column = [0] * w 

for i in range(h):
    if ma[i] == ['.'] * w:
      row[i] = 1

j = 0
while j < w:
    count = 0
    for i in range(h):
        if ma[i][j] == '.':
            count += 1
        if count == h:
            column[j] = 1
    j += 1

for i in range(h):
    if row[i] == 1:
        for j in range(w):
            ma[i][j] = ''

for j in range(w):
    if column[j] == 1:
        for i in range(h):
            ma[i][j] = ''

for i in range(h):
    if ma[i].count('') == len(ma[i]): 
        continue
    else:
        print(''.join(ma[i]))