Problem:


Score : 200 points

Problem Statement

There is a grid of squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Each square is black or white.
The color of the square is given as an H-by-W matrix (a_{i, j}).
If a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.

Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:

Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.

It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#



Sample input:
4 4
##.#
....
##.#
.#.#


Sample output:
###
###
.##

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    H, W = map(int, input().split())
    a = []
    for i in range(H):
        tmp = str(input())
        if "#" in tmp:
            a.append(tmp)
    binary = [1]*W
    for i in range(len(a)):
        for j in range(W):
            if a[i][j] == "#":
                binary[j] = 0
    for i in range(len(a)):
        tmp = ""
        for j, b in enumerate(binary):
            if b == 0:
                tmp += a[i][j]
        print(tmp)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

L2=[]
for i in range(h):
      if "#" in L[i]:
            L2.append(list(L[i]))
            
flag=[]
for i in range(w):
      for j in range(len(L2)):
            if L2[j][i]=="#":
                  flag.append(i)
                  break
ans=[]
ans2=[]
for i in range(len(L2)):
      for j in flag:
            ans2.append(L2[i][j])
      ans.append(ans2)
      ans2=[]

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

Submission status: Accepted

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

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

x = 0
for h in range(H-1, -1, -1):
    if A[h].count('.') == W:
        del A[h]
        x += 1

for w in range(W-1, -1, -1):
    count = 0
    for h in range(H-x):
        if A[h][w] == '.':
            count += 1
    if count == H-x:
        for h in range(H-x-1, -1, -1):
            del A[h][w]

for h in range(H-x):
    print(''.join(A[h]))

Submission status: Accepted

Solution code:
import numpy as np

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

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

count = 0
li_2 = []
for i in range(h):
    for j in range(w):
        if li[i][j] == '#':
            li_2.append(list(li[i][:]))
            count += 1
            break
li_3 = []
li_2 = [list(x) for x in zip(*li_2)]

count2= 0
for j in range(w):
    for k in range(count):
        if li_2[j][k] == '#':
            li_3.append(li_2[j][:])
            count2 += 1
            break


li_3 = [list(y) for y in zip(*li_3)]

for i in range(count):
    for j in range(count2):
        print(li_3[i][j], end='')
        if j == count2-1:
            print('')

Submission status: Accepted

Solution code:
#実装が200点としては重い
h,w = map(int, input().split( ))

a_ = []

for i in range(h):
    ai = input()
    if ai!='.'*w:
        a_.append(ai)
#print(a_)
h = len(a_)

a = [[a_[i][j] for j in range(w)] for i in range(h)]
#print(a)
rmv = set()
for j in range(w):
    flag = True
    for i in range(h):
        if a[i][j] =="#":
            flag = False
            break
    if flag:
        rmv.add(j)
#print(rmv)
for i in range(h):
    rem = []
    for j in range(w):
        if j not in rmv:
            rem.append(a[i][j])
    print("".join(rem))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
mat = []
mat_1 = []
mat_2 = []
mat_3 = []
mat_4 = []

for i in range(h):
    line = list(input())
    mat.append(line)
# print(mat)

# すべて白の行を削除
for i in range(h):
    line = mat[i]
    if line.count(".") != w:
        mat_1.append(line)

# print(mat_1)

# 転置
for line in zip(*mat_1):
    mat_2.append(list(line))

# print(mat_2, len(mat_2))
# すべて白の行を削除
for i in range(len(mat_2)):
    line = mat_2[i]
    if line.count(".") != len(mat_2[0]):
        mat_3.append(line)

# print(mat_3)

# 転置
for line in zip(*mat_3):
    mat_4.append(list(line))

# 出力
for line in mat_4:
    print(*line, sep="")

Submission status: Accepted

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

al_l = []

for _ in range(h):
    al = list(input())
    al_l.append(al)


for al in al_l:
    for idx, a in enumerate(al):
        tmp = [i[idx] for i in al_l]
        if "#" not in al or "#" not in tmp:
            pass
        else:
            print(a, end="")
    print("")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
T = list(map(str, input()))
dic = {}
M = []
M.append(T)
for i in range(W):
    if T[i] == '.':
        dic[i] = 1
for i in range(H-1):
    T = list(map(str, input()))
    for j in range(W):
        if T[j] == '.' and j in dic:
            dic[j] += 1
    M.append(T)

for i in range(H):
    t = 0
    for j in range(W):
        if M[i][j] == '.':
            t += 1
        if j in dic and dic[j] == H:
            M[i][j] = ''
    if not t == W:
        print(''.join(M[i]))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
  h, w = MAP()
  a = [list(input()) for _ in range(h)]
  g = []
  r = []
  for i in range(h):
    for j in range(w):
      if a[i][j] == "#":
        g.append(i)
        r.append(j)
  g = set(g)
  r = set(r)
  #print(g)
  #print(r)
  for i in g:
    for j in r:
      print(a[i][j], end='')
    print()

if  __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
a = [list(input()) for _ in range(H)]

# a = [s for s in a if s != ["."]*W]

# b = [[0]*len(a) for _ in range(len(a[0]))]
# for i in range(len(a)):
# 	for j in range(len(a[0])):
# 		b[j][i] = a[i][j]

# b = [s for s in b if s != ["."]*len(b[0])]

# c = [[0]*len(b) for _ in range(len(b[0]))]

# for i in range(len(b)):
# 	for j in range(len(b[0])):
# 		c[j][i] = b[i][j]

# for s in c:
# 	print("".join(s))

gyou = set()
retu = set()

for i in range(H):
	for j in range(W):
		if a[i][j] == "#":
			retu.add(j)
			gyou.add(i)


for g in gyou:
	for r in retu:
		print(a[g][r], end="")
	print()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
a = [list(input()) for _ in range(H)]

a = [s for s in a if s != ["."]*W]

b = [[0]*len(a) for _ in range(len(a[0]))]
for i in range(len(a)):
	for j in range(len(a[0])):
		b[j][i] = a[i][j]

b = [s for s in b if s != ["."]*len(b[0])]

c = [[0]*len(b) for _ in range(len(b[0]))]

for i in range(len(b)):
	for j in range(len(b[0])):
		c[j][i] = b[i][j]

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

Submission status: Accepted

Solution code:
# ABC 107: B – Grid Compression
h, w = [int(s) for s in input().split()]
a = [input() for _ in range(h)]

grid_after_operations = []

for i in range(h):
    if a[i] != '.' * w:
        grid_after_operations.append(a[i])

for j in reversed(range(w)):
    if grid_after_operations[0][j] == '.':
        for i in range(1, len(grid_after_operations)):
            if grid_after_operations[i][j] != '.':
                break
        else:
            for i in range(len(grid_after_operations)):
                grid_after_operations[i] = grid_after_operations[i][:j] + grid_after_operations[i][j + 1:]

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

h,w= [int(x) for x in stdin.readline().rstrip().split()]

li = [["" for i in range(w)]for j in range(h)]

for i in range(h):
    s = stdin.readline().rstrip()
    for j in range(w):
        li[i][j] = s[j]

li = np.asarray([s for s in li if s != ['.']*w]).T.tolist()
li = np.asarray([s for s in li if s != ['.']*len(li[0])]).T.tolist()

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

Submission status: Accepted

Solution code:
hw = [int(i) for i in input().split()]
a = [list(input()) for _ in range(hw[0])]
for i in range(2):
  c = 0
  for ai in a:
    if all([aij == "." for aij in ai]):
      c += 1
  for j in range(c):
    a.remove(["."] * len(a[i]))
  a = [list(ai) for ai in zip(*a)]
for ai in a:
  print("".join(ai))

Submission status: Accepted

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

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            ver[j]=True
            hor[i]=True

for i in range(h):
    if hor[i]:
        for j in range(w):
            if ver[j]==True:
                print(a[i][j],end="")
        print()

Submission status: Accepted

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

for i in reversed(range(h)):
  if all(j=="." for j in l[i]):
    l.pop(i)
for i in reversed(range(w)):
  if all(j[i]=="." for j in l):
    for j in l:
      j.pop(i)
for i in l:
  print(''.join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(input()))
j=0
lis=[]
l=[]
count=0
for i in range(h):
    for j in range(w):
        if a[i][j]!='.':
            break
        if j==w-1:
            l.append(i)
x=0
while x<len(l):
    del a[l[x]-count]
    count+=1 
    x+=1
#print(a)
for k in range(len(a)):
    for l in range(w):
        if a[k][l]=='.':
            c=0
            while c<len(a):
                if a[c][l]!='.':
                    break
                if c==len(a)-1 and l not in set(lis):
                    lis.append(l)
                c+=1
ans=''
#print(lis)
tmp=0
count=0
for o in range(len(lis)):
    tmp=lis[o]
    for s in range(len(a)):
        del a[s][tmp-count]
    count+=1    
for q in range(len(a)):
    for e in range(len(a[0])):
        ans+=a[q][e]
    print(ans)
    ans=''

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for i in range(h)]
b=[]
for i in range(h):
    ans=True
    for j in range(w):
        if a[i][j]=='#':
            ans=False
    if ans:
        b.append(i)
for i in reversed(b):
    a.pop(i)
h-=len(b)
for j in range(w-1,-1,-1):
    ans=True
    for i in range(h-1,-1,-1):
        if a[i][j]=="#":
            ans=False
    if ans:
        for i in range(h-1,-1,-1):
            a[i]=a[i][:j]+a[i][j+1:]
for i in range(h):
    print(a[i])

Submission status: Accepted

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

mat = []
for i in range(h):
    row = input()
    mat.append(row)

mat2 = []
for row in mat:
    isAllWhite = True
    for x in row:
        if x == '#':
            isAllWhite = False
            break
    if not isAllWhite:
        mat2.append(row)

hh = len(mat2)
mat3 = [[] for i in range(hh)]
for i in range(w):
    isAllWhite = True
    for j in range(hh):
        if mat2[j][i] == '#':
            isAllWhite = False
            break
    if not isAllWhite:
        for j in range(hh):
            mat3[j].append(mat2[j][i])

for row in mat3:
    print("".join(row))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
	a.append(input())
ind1 = []
for i in range(h):
	if "#" in a[i][:]:
		ind1.append(i)
ind2 = []
for i in range(w):
	judge = 0
	for j in range(h):
		if "#" == a[j][i]:
			judge = 1
	if judge:
		ind2.append(i)
for i in range(len(ind1)):
	s = []
	for j in range(len(ind2)):
		s.append(a[ind1[i]][ind2[j]])
	print("".join(map(str, s)))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
a=[input() for i in range(H)]
l=[0]*W
for i in a:
    for j in range(W):
        if i[j]=="#":
            l[j]+=1
for i in a:
    if "#" in i:
        for j in range(W):
            if l[j]:
                print(i[j],end="")
        print()

Submission status: Accepted

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

for _ in range(100):
    for i, row in enumerate(a):
        if "#" not in row:
            a.pop(i)
            break

    for i, col in enumerate(zip(*a)):
            if "#" not in col:
                for j, row in enumerate(a):
                    a[j].pop(i)
                break

for row in a:
    for sign in row:
        print(sign, end="")
    print()

Submission status: Accepted

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

aa = [row for row in a if "#" in row]
aaa = [row for row in zip(*aa) if "#" in row]
for _ in zip(*aaa):
    print(*_, sep="")

Submission status: Accepted

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

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

for i in range(h):
    if row[i]:
        s = ''
        for j in range(w):
            if col[j]:
                s += lis[i][j]
        print(s)

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
a = [[c for c in input()] for i in range(h)]
a = np.array(a)
colums = []
rows = []
for i in range(h):
    if not np.all(a[i] == '.'):
        colums.append(i)
for i in range(w):
    if not np.all(a[:, i] == '.'):
        rows.append(i)
a = a[colums]
for l in a[:, rows]:
    print(''.join(l))

Submission status: Accepted

Solution code:
from copy import deepcopy
H, W = map(int, input().split())
alist = [list(input()) for _ in range(H)]
acopy = deepcopy(alist)
counter = 0
for i in range(W):
    for a in alist:
        if a[i] == "#":
            break
    else:
        for a in acopy:
            a.pop(i - counter)
        counter += 1

for a in acopy:
    if "#" in a:
        print("".join(a))

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-09 16:39:51(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

def main():
    h, w = (int(x) for x in sys.stdin.readline().split())
    a = [list(sys.stdin.readline().rstrip()) for _ in range(h)]
    
    for i in range(len(a)-1, -1, -1):
        for j in range(len(a[0])-1, -1, -1):
            if a[i][j] == '#':
                break
        else:
            del a[i]

    for j in range(len(a[0])-1, -1, -1):
        for i in range(len(a)-1, -1, -1):
            if a[i][j] == '#':
                break
        else:
            for i in range(len(a)-1, -1, -1):
                del a[i][j]

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

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
  
flag = True
cols = []
rows= []
  
for i in range(0, H):
  flag = True
  for j in range(0, W):
    if S[i][j] == '#':
      flag = False
  if flag:
    cols.append(i)

for i in range(0, W):
  flag = True
  for j in range(0, H):
    if S[j][i] == '#':
      flag = False
  if flag:
    rows.append(i)
      
for i in range(0, H):
  for j in range(0, W):
    if i not in cols and j not in rows:
      print(S[i][j], end="")
  if i not in cols:
    print()

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import numpy as np

H,W=two_int()



output = []
for i in range(H):
    row = list(one_str())

    temp = list(set(row))
    if temp[0]=="." and len(temp)==1:
        continue
    
    output.append(row)

output = np.asarray(output).T



fin=[]
for row in output:
    temp = list(set(row))
    if temp[0]=="." and len(temp)==1:
        continue
    
    fin.append(row)
output = np.asarray(fin).T


for row in output:
    print("".join(row))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = [ input() for _ in range(h) ]
whitew, whiteh = "." * w, "." * h
temph, tempw = 0, 0
for i in range(h):
  if A[i-temph] == whitew:
    A.pop(i-temph)
    temph += 1
    h -= 1
for i in range(w):
  b = True
  for j in range(h):
    if A[j][i-tempw] != ".":
      b = False
  if b:
    for j in range(h):
      A[j] = A[j][:i-tempw] + A[j][i-tempw+1:]
    tempw += 1
    w -= 1
for i in range(h):
  print(A[i])

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
A = [list(map(str,input())) for i in range(h)]
for k in range(max(h,w)):
    counter = 0
    for i in range(h):
        if '#' not in A[i-counter]:
            del(A[i-counter:i-counter+1])
            counter += 1
            h -= 1
        if i-counter >= h-1:
            break
    counter = 0
    B = [list(row) for row in zip(*A)]
    for j in range(w):
        if '#' not in B[j-counter]:
            del(B[j-counter:j-counter+1])
            counter += 1
            w -= 1
        if j-counter >= w-1:
            break
    A = [list(row) for row in zip(*B)]
for row in A:
    print(*row, sep='')

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(H):
    for j in range(W):
        if A[i][j]=='#':
            Tate[i]+=1
            Yoko[j]+=1

ans=['']*H
for i in range(H):
    for j in range(W):
        if Tate[i]*Yoko[j]>0:
            ans[i]+=A[i][j]

for i in ans:
    if i!='':
        print(i)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import re
H, W = map(int, input().split())
l = []
for i in range(H):
  a = input()
  if(len(re.findall('#', a)) != 0):
    l.append(a)
#print(l)

hh = len(l)
l2 = []
for j in range(W):
  if(l[0][j] == '.'):
    flag = 0
    for k in range(hh):
      if(l[k][j] == '#'):
        flag = 1
    if(flag == 0):
      l2.append(j)
#print(l2)

l3 = list(range(W))
#print(l3)
l4 = list(set(l3) - set(l2))
#print(l4)

for k in range(hh):
  a = ''
  for ll in l4:
   #print(l[k][ll]) 
   a = a + l[k][ll]
  print(a)

Submission status: Accepted

Solution code:
H, W = [int(x) for x in input().split()]
rows = [input() for _ in range(H)]
lst = []
tmp = []
for row in rows:
    if '#' in row: lst.append(row)
for i in range(W):
    column = ''
    for row in lst:
        column += row[i]
    if '#' not in column: 
        tmp.append(i)
for row in lst:
    for i in range(W):
        if (i in tmp): continue
        print(row[i], end='')
    print()

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
grid = [list(input()) for i in range(h)]
for i in reversed(range(h)):
    if all(j=="." for j in grid[i]):
        grid.pop(i)
for i in reversed(range(w)):
    if all(j[i]=="." for j in grid):
        for j in grid:
            j.pop(i)
for i in grid:
    print("".join(i))

Submission status: Accepted

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

A = []
for i in range(H):
  A_i = input()
  A.append(A_i)
  for j, a in enumerate(A_i):
    if a == "#":
      bl_H[i] = True
      bl_W[j] = True

for i, h in enumerate(bl_H):
  for j, w in enumerate(bl_W):
    if h and w:
      print(A[i][j], end="")
  if h:
    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())

a = [list(input()) for i in range(h)]
a = [x for x in a if "#" in x]

aT = list(zip(*a))
aT = [x for x in aT if "#" in x]

a = list(zip(*aT))

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

Submission status: Accepted

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

for i in range(H):
    a=list(input())
    if a.count("#")!=0:
        l.append(a)

l1=list(zip(*l))
i=0
while i < len(l1):
    if l1[i].count("#")!=0:
        l2.append(l1[i])
    i+=1
l3=list(zip(*l2))
for i in range(len(l3)):
    print("".join(l3[i]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
b = [x for x in a if "#" in x]
#print(*b)
c = zip(*[y for y in zip(*b) if "#" in y])
#print(list(c))
for d in c:
  print("".join(d))

Submission status: Accepted

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

for i in range(h):
  s=input()
  if '#' in s:
    l.append(s)
    for j in range(w):
      p[j] *= 1 if s[j]=='.' else 0

for i in range(len(l)):
  for j in range(w):
    if p[j]==0:
      print(l[i][j],end='')
  print()

Submission status: Accepted

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

ans = []
# 横白の除去
for h in range(H):
    line = input()
    if "#" in line:
        ans.append(line)


lines = zip(*ans)
ans = []
# 縦白の除去
for line in lines:
    if "#" in line:
        ans.append(line)

an = zip(*ans)

for line in an:
    print(''.join(line))

Submission status: Accepted

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

ans = []
# 横白の除去
for h in range(H):
    line = input()
    if "#" in line:
        ans.append(line)

H = len(ans)
W = len(ans[0])

# 縦白の除去
rem_list = []
for w in range(W):
    ver = [s[w] for s in ans]
    if "#" in ver:
        continue
    rem_list.append(w)

for h in range(H):
    new_ans = []
    for w in range(W):
        if w in rem_list:
            continue
        new_ans.append(ans[h][w])
    ans[h] = new_ans

for i in range(len(ans)):
    for j in range(len(ans[0])):
        print(ans[i][j], end="")
        if j >= len(ans[0])-1:
            print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
l=[x for x in s if '#' in x]
ans=[]
for i in zip(*l):
  if '#' in i:ans.append(i)
an=zip(*ans)
for x in an:
  print(''.join(x))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [list(input()) for i in range(H)]
ver = []
hor = []
for j in range(W):
    tmp = []
    for i in range(H):
        tmp.append(a[i][j])
    if tmp == ["."]*H:
        ver.append(j)
for i in range(H):
    if a[i] == ["."]*W:
        hor.append(i)
ver = list(set(list(range(W)))-set(ver))
hor = list(set(list(range(H)))-set(hor))
ans = []
for i in hor:
    tmp = []
    for j in ver:
        tmp.append(a[i][j])
    ans.append(tmp)
for i in range(len(ans)):
    print("".join(ans[i]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = list()
#入力
for i in range(H):
	a_line = list(input())
	a.append(a_line)

ans = list()
#全部白の行を削除
for line in a:
	if {'#'} <= set(line):
		ans.append(line)

column_list = list()
# 列
for column in range(len(ans[0])):
	count = 0
	# 行
	for line in ans:
		if line[column] == '.':
			count += 1
		else:
			count = 0
			break
	if count == len(ans):
		column_list.append(column)

column_list.sort(reverse=True)

for line_num in range(len(ans)):
	for pop_column in column_list:
		ans[line_num].pop(pop_column)

for line in ans:
	print(''.join(line))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
g = []
cols = set()
for _ in range(H):
    r = input()
    if r != "." * W:
        g.append(r)
        for i in range(W):
            if r[i] == "#":
                cols.add(i)
cols = sorted(cols)
for r in g:
    print(*[r[i] for i in cols], sep="")

Submission status: Accepted

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

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]

    else:
        i += 1
    if i > len(HW_list[0]) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
g = []
for _ in range(h):
    r = input()
    if r != "."*w:
        g.append(r)

gg = ["" for _ in range(len(g))]

for i in range(w):
    if "".join([g[j][i] for j in range(len(g))]) != "." * len(g):
        for j in range(len(g)):
            gg[j] += g[j][i]
print(*gg, sep="\n")

Submission status: Accepted

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

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

flag = False
for j in range(W-1, -1, -1):
    for i in range(len(a)):
        if a[i][j] == "#":
            flag = True
    if not flag:
        for i in range(len(a)):
            a[i] = a[i][:j] + a[i][j+1:]
    flag = False

for b in a:
    print(b)

Submission status: Accepted

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

b=[]
for x in a:
  if "#" in x:
    b.append(x)

c=[]
for y in zip(*b):
  if "#" in y:
    c.append(y)
c1=[]
c1=zip(*c)
    
#c=zip(*[y for y in zip(*b) if "#" in y])

for d in c1:
  print("".join(d))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    wi = input()
    if wi != "."*w:
        a.append(wi)
b = zip(*[x for x in zip(*a) if "#" in x])
for i in b:
    print("".join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    wi = input()
    if wi != "."*w:
        a.append(wi)
b = []
for j in range(w):
    wi2 = ""
    for i in range(len(a)):
        wi2 += a[i][w-j-1]
    if wi2 != "."*len(a):
        b.append(wi2)
ans = []
for i in range(len(b[0])):
    hi3 = ""
    for j in range(len(b)):
        hi3 += b[len(b)-j-1][i]
    print(hi3)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
gr = []
for i in range(H):
	w = input()
	if set(w) == {"."}:
		pass
	else:
		gr.append(w)

gr = [list(x) for x in zip(*gr)]
GR = []
for j in range(W):
	w = gr[j]
	if set(w) == {"."}:
		pass
	else:
		GR.append(w)
GR = [list(x) for x in zip(*GR)]
for i in range(len(GR)):
	print("".join(GR[i]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(input())[: -1] for _ in range(H)]
b = []
c = set()
#print(a)
for i in range(H):
  f = 1
  for j in range(W):
    if a[i][j] == ".":
      f = 0
    else:
      f = 1
      break
  if f: b.append(a[i])
#print(b)
for j in range(W):
  f = 0
  for i in range(len(b)):
    if b[i][j] == ".":
      f = 1
    else:
      f = 0
      break
  if f: c.add(j)
#print(c)
for i in range(len(b)):
  res = ""
  for j in range(W):
    if j in c:
      continue
    res += b[i][j]
  print(res)

Submission status: Accepted

Solution code:
def removeRow(s, i):
  return s[:i] + s[i+1:]

def removeCol(s, j):
  for i in range(len(s)):
    s[i] = s[i][:j] + s[i][j+1:]
  return s

def isWhiteRow(s, i):
  return s[i].count("#") == 0

def isWhiteCol(s, j):
  res = True
  for i in range(len(s)):
    res &= s[i][j] == "."
  return res

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

while True:
  changed = False
  for i in range(len(a)):
    if isWhiteRow(a, i):
      a = removeRow(a, i)
      changed = True
      break
  for j in range(len(a[0])):
    if isWhiteCol(a, j):
      a = removeCol(a, j)
      changed = True
      break
  if not changed:
    for s in a:
      print(s)
    exit()

Submission status: Accepted

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

nrow = len(mat[0])
row_checked_mat = [row for row in mat if not row.count('.') == nrow]

ncol = len(row_checked_mat)
col_checked_mat = [col for col in zip(*row_checked_mat) if not col.count('.') == ncol]

for mat_i in zip(*col_checked_mat):
  print(*mat_i, sep='')

Submission status: Accepted

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

l=[]
for j in range(W):
  b = [x[j] for x in a]
  if '#' in b:
    #print(b)
    l.append(b)
    

for k2 in range(len(l[0])):
  for k in range(len(l)):
  	print(l[k][k2],end='')
  print("")