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:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

H,W = inpl()
MAP = [list(input()) for i in range(H)]
xx = []
yy = []

for x in range(W):
	for y in range(H):
		if MAP[y][x] == '.':
			continue
		else:
			break
	else:
		xx.append(x)

for y in range(H):
	for x in range(W):
		if MAP[y][x] == '.':
			continue
		else:
			break
	else:
		yy.append(y)

ans = []
for y in range(H):
	if y in yy:
		continue
	tmp = []
	for x in range(W):
		if x in xx:
			continue
		tmp.append(MAP[y][x])
	ans.append(tmp)

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

Submission status: Accepted

Solution code:
# coding: utf-8

def getList(H, W, A):
    rList = [0] * H
    cList = [0] * W
    for r in range(H):
        for c in range(W):
            if A[r][c] == "#":
                rList[r] += 1
                cList[c] += 1
    return rList, cList

def getTargetList(tList):
    zeroList = []
    for i in range(len(tList)):
        if tList[i] == 0:
            zeroList.append(i)
    return zeroList
    
def delRow(A, tList):
    for r in reversed(tList):
        A.pop(r)
    return A

def delCol(A, tList):
    for c in reversed(tList):
        for r in range(len(A)):
            A[r].pop(c)
    return A

def solve(H, W, A):
    rList, cList = getList(H, W, A)
    A = delRow(A, getTargetList(rList))
    A = delCol(A, getTargetList(cList))
    return A
    
if __name__ == "__main__":
    H, W = map(int, input().split())
    A = []
    for i in range(H):
        tmp = input()
        A.append([])
        for s in tmp:
            A[i].append(s)

    A = solve(H, W, A)
    for i in A:
        for j in i:
            print(j, end="")
        print()

Submission status: Accepted

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

import numpy as np

matrix = np.empty((0, W), str)
for i in range(0, H):
    matrix = np.append(matrix, np.array([list(input())]), axis = 0)
matrix = matrix[:, np.any(matrix != ".", axis = 0)]
matrix = matrix[np.any(matrix == "#", axis = 1), :]
H, W = matrix.shape
for i in range(0, H):
    print(''.join(matrix[i, :]))

Submission status: Accepted

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

    # ans = f(H, W, a)
    # ans = T(H, W, a)
    ans = editorial(H, W, a)
    for x in ans:
        print(*x, sep="")


def editorial(H, W, a):
    # 出力する部分の記憶
    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

    ans = []
    for i in range(H):
        if not row[i]:
            continue

        line = []
        for j in range(W):
            if col[j]:
                line.append(a[i][j])
        ans.append(line)

    if not ans:
        return [[]]

    return ans


def T(H, W, a):
    """
    転置
    本番ではバグらせるのを恐れて愚直に実装した
    """
    b = []
    c = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    for line in zip(*b):
        if len(line) != line.count("."):
            c.append(line)

    if not c:
        return [[]]

    return list(zip(*c))


def f(H, W, a):
    b = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    if not b:
        return [[]]

    idxes = []
    for x in range(len(a[0])):
        y = sum(1 for i in range(len(b)) if b[i][x] == ".")
        if y != len(b):
            idxes.append(x)

    if not idxes:
        return [[]]

    ans = []
    for i in range(len(b)):
        line = []
        for j in range(len(a[0])):
            if j in idxes:
                line.append(b[i][j])
        ans.append(line)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def delete(array):
    for i in range(len(array) - 1, -1, -1):
        if ''.join(list(set(list(array[i])))) == '.':
            del array[i]

delete(array)
array = list(map(list, zip(*array)))
delete(array)
array = list(map(list, zip(*array)))

for i in range(len(array)):
    print (''.join(array[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
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:
str = input()
a,b = [int(x) for x in str.split()]
r = [0] * a
c = [0] * b
s = []
for i in range(0,a):
	str = input()
	s.append(str)
	for j in range(0,b):
		if str[j] == '#':
			r[i] += 1
			c[j] += 1
for i in range(0,a):
	if r[i] != 0:
		str = s[i]
		for j in range(0,b):
			if c[j] != 0:
				print(str[j],end="")
		print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#107b
import numpy as np

def trans(l):
    l=np.array(l)
    l=l.T
    l=l.tolist()
    return l

h,w=map(int,input().split())
temp1=[]
temp2=[]
ans=[]

for i in range(h):
    ans.append(list(input()))

for i in ans[:]:
    if set(i)!={'.'}:
        temp1.append(i)

     
ans=trans(temp1)

for i in ans[:]:
    if set(i)!={'.'}:
        temp2.append(i)

ans=trans(temp2)
        
for i in ans:
    print(''.join(i))

Submission status: Accepted

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

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

arr_temp01=[]
for i in range(1,1+h):
    
    if arr_data[i][0]!= w * ".":
        
        arr_temp01.append(arr_data[i][0]) 
    else:
        h-=1

arr_temp02=[]
for v in list(zip(*arr_temp01)):
    
    if "".join(v) != h*".":
    
        arr_temp02.append("".join(v))
    else:
        w-=1
        
for v in list(zip(*arr_temp02)):
    
    print("".join(v))

Submission status: Accepted

Solution code:
s = [f for f in open(0).read().split() if '#' in f]
s = [''.join([s[j][i] for j in range(len(s))]) for i in range(len(s[0]))]
s = [f for f in s if '#' in f]
s = [''.join([s[j][i] for j in range(len(s))]) for i in range(len(s[0]))]
print(*s, sep='\n')

Submission status: Accepted

Solution code:
# Use numpy if you use column operation
import numpy as np
h, w =  map(int, input().split())

# Get grid colors
gird_colors = np.array([])
for _ in range(h):
    tmp_row = np.array(list(input()))
    if "#" in tmp_row: # If the row includes black
        gird_colors = np.concatenate((gird_colors, tmp_row))
gird_colors = gird_colors.reshape(-1, w)

# Search and delete white line
del_count = 0
for wi in range(w):
    if "#" not in gird_colors[:, wi - del_count]:
        gird_colors = np.delete(gird_colors, wi - del_count, 1)
        del_count += 1

# Print result
for line_val in gird_colors:
    print("".join(line_val))

Submission status: Accepted

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

def checkLine(_h,_w):
  flag = True
  for i in range(0,h):
    if a[i][_w] == '#':
      flag = False

  if flag:
    return True

  flag = True
  for i in range(0,w):
    if a[_h][i] == '#':
      flag = False

  if flag:
    return True

  return False

a = []
for i in range(0,h):
  a += input().split()

for i in range(0,h):
  str = ""
  for j in range(0,w):
    if checkLine(i,j) == False:
      str = str + a[i][j]
  if str != "":
    print(str)

Submission status: Accepted

Solution code:
H,W = map(int,input().split(" "))
field = []
row_0 = ["." for i in range(W)]
for i in range(H):
    row_i = list(input())
    if row_i == row_0:
        H -= 1
    else:
        field.append(row_i)
col_0 = ["." for i in range(H)]
for i in range(W)[::-1]:
    col_i = []
    for j in range(H):
        col_i.append(field[j][i])
    if col_i == col_0:
        for j in range(H):
            del field[j][i]

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
d=[list(input())  for i in range(h)]
for i in range(w)[::-1]:
    if not "#" in [d[j][i] for j in range(h)]:
        for j in range(h):del d[j][i]
for i in d:
    if "#" in i:print(*i,sep="")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
grid=[list(input())  for i in range(h)]
for i in range(w)[::-1]:
    a=[grid[j][i] for j in range(h)]
    if not "#" in a:
        for j in range(h):
            del grid[j][i]
for i in grid:
    if "#" in i:print(*i,sep="")

Submission status: Accepted

Solution code:
import sys
y = input().split()
H = int(y[0])
W = int(y[1])
x = list()
for i in range(H):
    x.append(input())

flagH = list()
flagW = list()
for i in range(H):
    flagH.append(False)
for j in range(W):
    flagW.append(False)

for i in range(H):
    for j in range(W):
        if x[i][j] == "#":
            flagH[i] = True
            flagW[j] = True

for i in range(H):
    for j in range(W):
        if flagH[i] and flagW[j]:
            sys.stdout.write(x[i][j])
    if flagH[i]:
        print()

Submission status: Accepted

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

ah, aw = [0] * h, [0] * w
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            ah[i] = aw[j] = True
ans = ''
for i in range(h):
    for j in range(w):
        if ah[i] and aw[j]:
            ans += a[i][j]
    if ah[i]:
        ans += '\n'
print(ans)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = []
for i in range(H):
    a.append(input().split())
g = []
r = []
for i in range(H):
    for j in range(W):
        if a[i][0][j] == "#":
            g.append(i)
            break
#print(g)
for i in range(W):
    for j in range(H):
        if a[j][0][i] == "#":
            r.append(i)
            break
#print(r)
ans = ""
for i in g:
    for j in r:
        ans += a[i][0][j]
    print(ans)
    ans = ""

Submission status: Accepted

Solution code:
h, w = input().split()
h = int(h)
w = int(w)
lines = list()
c = [0]*w
for _ in range(h):
    line = input()
    if line=="."*w:
        continue
    lines.append(line)
    for i in range(w):
        if line[i]==".":
            c[i] += 1
h = len(lines)
ans = list()
for j in range(h):
    line = ""
    for i in range(w):
        if c[i] != h:
            line += lines[j][i]
    ans.append(line)
print("\n".join(ans))

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
a=[input() for _ in range(h)]
ta=[]
tb=[]
tc=[]
for x in a:
    j=False
    for y in x:
        if y=='#':
            j=True
    if j:
        ta.append(x)
for i in range(1,w+1):
    t=[ta[j][-i] for j in range(len(ta))]
    j=False
    for x in t:
        if x=='#':
            j=True
    if j:
        tb.append(t)
for i in range(len(tb[0])):
    t=[tb[-j][i] for j in range(1,len(tb)+1)]
    print("".join(t))

Submission status: Accepted

Solution code:
H,W = (int(i) for i in input().split())

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

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

count = 0
check = []
n = 0
for i in range(H):
    for j in range(W):
        if a[i-n][j] == '#':
            count = 1
            break
    if count == 0:
        del a[i-n]
        n += 1
    count = 0

ck = []
n = 0
for i in range(W):
    for j in range(len(a)):
        if a[j][i] == '#':
            count = 1
            break
    if count == 0:
        ck.append(i)
    count = 0

for i in ck:
    for j in range(len(a)):
        del a[j][i-n]
    n += 1

ans = ''
for i in range(len(a)):
    for j in a[i]:
        ans += j
    print(ans)
    ans = ''

Submission status: Accepted

Solution code:
#ABC-B_not debuged
H, W = map(int, input().split())
a, ans = [], []
for i in range(H):
    temp = input()
    if temp == '.'*W:
        continue
    a.append(temp)
    ans.append([])

for i in range(W):
    for j in a:
        if j[i] == '#':
            break
    else:
        continue
    for j,k in zip(a,ans):
        k.append(j[i])
for i in ans:
    print(''.join(i))

Submission status: Accepted

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

#行を削除
i = 0
counter = 0
line = 0
while counter < h:
    k = 0
    check = True
    while k<w and check:
        if a[i][k] == "#":
            check = False
        else:
            k += 1
    if check:
        a.pop(i)
        line += 1
    else:
        i += 1
    counter += 1

#列を削除
i = 0
k = 0
counter = 0
while counter < w:
    i = 0
    check = True
    while i < h-line and check:
        if a[i][k] == "#":
            check = False
        else:
            i += 1
    if check:
        for j in range(len(a)):
            a[j].pop(k)
    else:
        k += 1
    counter += 1

for i in range(len(a)):
    for k in range(len(a[i])):
        if k != len(a[i]) -1:
            print(a[i][k],end = "")
        else:
            print(a[i][k])

Submission status: Accepted

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

rm_h = [i for i, line in enumerate(grid) if all([x == '.' for x in line])]

rm_w = [i for i in range(w) if all([grid[j][i] == '.' for j in range(h)])]

arc_grid = [[grid[j][i] for i in range(w) if not i in rm_w] for j in range(h) if not j in rm_h]
for i in range(h-len(rm_h)):
  for j in range(w-len(rm_w)):
    print(arc_grid[i][j], end='')
  print('')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)


h, w = f()
grid = []
row = [False for _ in range(h)]
column = [False for _ in range(w)]

for i in range(h):
    ro = input()
    row[i] = (ro == '.' * w)
    grid.append(list(ro))

for j in range(w):
    column[j] = all([(grid[k][j] == '.') for k in range(h)])

for i in range(h):
    if row[i]:
        continue
    for j in range(w):
        if not column[j]:
            print(grid[i][j], end='')
    print()

Submission status: Accepted

Solution code:
# coding:utf-8

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

h, w = inpl()
A = []
for i in range(h):
    a = list(input())
    A.append(a)

rows = [False for _ in range(h)]
for i in range(h):
    if A[i] != ['.' for _ in range(w)]:
        rows[i] = True

B = list(map(list, zip(*A)))[:]  # map(list, zip(* A))としておかないとタプル型になってしまう
cols = [False for _ in range(w)]
for i in range(w):
    if B[i] != ['.' for _ in range(h)]:
        cols[i] = True

ans = []
for i in range(h):
    if rows[i]:
        tmp = []
        for j in range(w):
            if cols[j]:
                tmp.append(A[i][j])
        if tmp:
            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 = [input() for _ in range(H)]
row = [False] * H
col = [False] * W
for i in range(len(row)):
  for j in range(len(col)):
    if a[i][j] == '#':
      row[i] = col[j] = True

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

Submission status: Accepted

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


for y in range(H):
    flag = True
    for x in range(W):
        if a[y][x] == "#":
            flag = False
            break
    if flag:
        h.append(y)

for x in range(W):
    flag = True
    for y in range(H):
        if a[y][x] == "#":
            flag = False
            break
    if flag:
        w.append(x)

for y in range(H):
    for x in range(W):
        if y not in h and x not in w:
            print(a[y][x], end="")
    if y not in h:
        print()

Submission status: Accepted

Solution code:
arr = []

h, w = [int(i) for i in input().split()]
for _ in range(h):
    arr.append(input())

result = []
for ar in arr:
    if not '#' in ar:
        continue
    result.append(ar)

h = len(result)
w = len(result[0])


# print(result)
# print(h, w)

result2 = []
for j in range(w):
    flag = True
    for i in range(h):
        if result[i][j] == '#':
            flag = False
    if flag:
        result2.append(j)

if result2:

    result3 = []
    for s in result:
        line = ''
        for i, c in enumerate(s):
            if i in result2:
                continue
            line += c
        result3.append(line)
else:
    result3 = result


# print()
# print(result)
# print(result2)
for line in result3:
    print(line)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
A = [a for a in A if "#" in a]
A = list(np.array(A).transpose())
A = [a for a in A if "#" in a]
A = list(np.array(A).transpose())
for a in A:
    print("".join(a))

Submission status: Accepted

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


for h in range(H):
    if '#' not in a[h]:
        for w in range(W):
            a[h][w] = ''
for w in range(W):
    if '#' not in [p[w] for p in a]:
        for h in range(H):
            a[h][w] = ''

for h in range(H):
    line = ''.join(a[h])
    if line:
        print(''.join(a[h]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
y = 0
while True:
    if y >= H:
        break
    x = 0
    A = list(input())
    cnt = 0
    while True:
        if x >= W:
            break
        if A[x] == ".":
            cnt += 1
        x += 1
    if cnt == W:
        H -= 1
    else:
        a.append(A)
        y += 1
x = 0
while True:
    if x >= W:
        break
    y = 0
    cnt = 0
    while True:
        if y >= H:
            break
        if a[y][x] == ".":
            cnt += 1
        y += 1
    if cnt == H:
        for i in range(H):
            del a[i][x]
        W -= 1
    else:
        x += 1

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

Submission status: Accepted

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

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

for i in range(H)[::-1]:
    if '#' not in a[i]:
        del a[i]
        H -= 1

n = []

for j in range(W)[::-1]:
    m = [''.join(t[j] for t in a)]
    if '#' in m[0]:
        n += m

for k in range(H):
    print(''.join(u[k] for u in n[::-1]))

Submission status: Accepted

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

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

for i in range(H)[::-1]:
    if '#' not in a[i]:
        del a[i]
        H -= 1

n = []

for j in range(W)[::-1]:
    m = [''.join([t[j] for t in a])]
    if '#' in m[0]:
        n += m

for k in range(H):
    print(''.join(u[k] for u in n[::-1]))

Submission status: Accepted

Solution code:
#abc107b

h,w=map(int,input().split())
a=[]
for i in range(h):
 t=input()
 if t=='.'*w:
  continue
 a.append(list(t))
b=list(map(list, zip(*a)))
c=[]
for i in range(len(b)):
 if all(x=='.' for x in b[i]):
  continue
 c.append(b[i])
l=list(map(list, zip(*c)))
for i in range(len(l)):
 print(''.join(l[i]))

Submission status: Accepted

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

table = []
row = [0 for _ in range(h)]
column = [0 for _ in range(w)]
for j in range(h):
    temp = [] + list(input())
    table.append(temp)
    check = 0
    for i in range(w):
        if temp[i] == '#':
            check = 1
            column[i] = 1
    row[j] = check

for i in range(h):
    if row[i] == 0:
        continue

    temp = [] + table[i]
    for j in range(w):
        if column[j] == 0:
            temp[j] = ''

    print(''.join(temp))

Submission status: Accepted

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

count=[0]*W

for i in b:

    for j in range(W):

        if i[j]=='#':
            count[j] += 1

ans=['']*len(b)

for i in range(len(b)):

    for j in range(W):

        if count[j]!=0:
            
            ans[i] += b[i][j]

for k in ans:

    print(k)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for _ in range(h):
  t = list(input())
  if t.count('.') != w:
    a.append(t)
i = 0
while True:
  if i >= len(a[0]):break
  for t in a:
    if t[i] != '.':
      i += 1
      break
  else:
    for j in range(len(a)):
      del a[j][i]
for t in a:
  print(''.join(t))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=list(input()for _ in[0]*h)
a=[0]*h
b=[0]*w
for i in range(h):
    f=0
    for j in range(w):f+=s[i][j]=='#'
    a[i]=f>0
for j in range(w):
    f=0
    for i in range(h):f+=s[i][j]=='#'
    b[j]=f>0
for i in range(h):
    if not a[i]:continue
    for j in range(w):
        if b[j]:print(s[i][j],end='')
    print()

Submission status: Accepted

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

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

wlist = []

flagc = [0 for i in range(W)]
for i in range(H):
    rtmp = str(input())
    rtmp_s = list(rtmp)

    flag = 0
    for j in range(len(rtmp_s)):
        if rtmp_s[j] == '#':
            flag += 1
            flagc[j] += 1

    if flag == 0:
        pass
    else:
        wlist.append(rtmp_s)


count = 0
for i in range(W):
    if flagc[i] == 0:
        count += 1

ans = []
for i in range(len(wlist)):
    ansr = []
    k = 0
    for j in range(W):
        if flagc[j] == 0:
            pass
        else:
            ansr.append(wlist[i][k])
        k += 1

    ans.append(ansr)


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

Submission status: Accepted

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

ans=[]

for i in range(H):
  ch=False
  for j in range(W):
    if A[i][j]=='#':
      ch=True
      break
  if ch:
    ans.append(A[i])

ans=list(zip(*ans))
ans1=[]

for i in range(W):
  ch=False
  for j in range(len(ans[i])):
    if ans[i][j]=='#':
      ch=True
      break
  if ch:
    ans1.append(ans[i])
    
ans1=list(zip(*ans1))

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

Submission status: Accepted

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

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

A = ["".join(row) for row in zip(*A) if row.count("#") > 0]
A = ["".join(row) for row in zip(*A) if row.count("#") > 0]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
H, W = map(int, input().split())
a = [None] * H
for i in range(H):
    a[i] = input()

c = [False] * W
r = [False] * H
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            break
        if j == W - 1:
            r[i] = True
for j in range(W):
    for i in range(H):
        if a[i][j] == '#':
            break
        if i == H - 1:
            c[j] = True

s = ''
for i in range(H):
    for j in range(W):
        if r[i] or c[j]:
            continue
        s += a[i][j]
    if not s:
        continue
    print(s)
    s = ''

Submission status: Accepted

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

a = list()
for height in range(H):
    line = input()
    if line == '.' * W:
        pass
    else:
        a.append(list(line))

# 転置して空白行を削除
a = [list(x) for x in zip(*a)]
a_trim = list()
for a_row in a:
    if ''.join(a_row) == '.' * len(a_row):
        pass
    else:
        a_trim.append(a_row)

a = [list(x) for x in zip(*a_trim)]  # 転置

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

Submission status: Accepted

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

h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()
	
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
			
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end='')
		print()

Submission status: Accepted

Solution code:

#"."だけで構成されている列があるかどうかの判定
#--------------------------------------------------------------------------------------------------------------------
def check_column(grid):
    H_temp = len(grid)
    W_temp = len(grid[0])
    column_index = []    
    for i in range(W_temp):
        count_dot_column = 0
        for j in range(H_temp):
            if grid[j][i] == ".":
                count_dot_column += 1
        # print(i)
        # print("grid:{}".format(grid))
        # print("count_dot_column:{}".format(count_dot_column))
        # print("Htemp:{}".format(H_temp))
        if count_dot_column == H_temp:
            column_index.append(i)
    if len(column_index) != 0:
        return True,column_index
    else:
        return False,column_index
#--------------------------------------------------------------------------------------------------------------------

#"."だけで構成されている列を削除
#--------------------------------------------------------------------------------------------------------------------
def del_column(grid,del_column_index):
    H_temp = len(grid)
    # print("del_cplumn_index={}".format(del_column_index))
    for i in range(H_temp):
        del grid[i][del_column_index]
    return grid
#--------------------------------------------------------------------------------------------------------------------




H,W = map(int,input().split())
grid = []
judge = True
# index = []
#"."のみで構成される行を削除
#--------------------------------------------------------------------------------------------------------------------
for i in range(H):
    temp_input = input()
    count_dot = temp_input.count(".")
    if count_dot == W:
        pass
    else:
        grid.append(list(temp_input))
# print(grid)
# print(len(grid))#Hの値が返ってくる
# print(len(grid[0]))#Wの値が返ってくる
#--------------------------------------------------------------------------------------------------------------------
while judge:
    judge,del_column_index = check_column(grid)
    # print(judge)
    if judge:
        # print("value")
        grid = del_column(grid, del_column_index[0])
        # print(del_column_index)
#結果を出力
#--------------------------------------------------------------------------------------------------------------------
# aprint()
for i in range(len(grid)):
    print("".join(grid[i]))
#--------------------------------------------------------------------------------------------------------------------

Submission status: Accepted

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

    # ans = f(H, W, a)
    ans = T(H, W, a)
    for x in ans:
        print(*x, sep="")


def T(H, W, a):
    """
    転置
    本番ではバグらせるのを恐れて愚直に実装した
    """
    b = []
    c = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    for line in zip(*b):
        if len(line) != line.count("."):
            c.append(line)

    if not c:
        return [[]]

    return list(zip(*c))


def f(H, W, a):
    b = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    if not b:
        return [[]]

    idxes = []
    for x in range(len(a[0])):
        y = sum(1 for i in range(len(b)) if b[i][x] == ".")
        if y != len(b):
            idxes.append(x)

    if not idxes:
        return [[]]

    ans = []
    for i in range(len(b)):
        line = []
        for j in range(len(a[0])):
            if j in idxes:
                line.append(b[i][j])
        ans.append(line)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = list(map(int, input().split()))
squareA = [list(input()) for i in range(H)]
squareB = [[squareA[i][j] for i in range(H)] for j in range(W)]
h = []
w = []
for i in range(H):
  if '#' not in squareA[i]:
    h.append(i)
for i in range(W):
  if '#' not in squareB[i]:
    w.append(i)
for i in range(H):
  if i not in h:
    for j in range(W):
      if j not in w:
        print(squareA[i][j], end = "")
    print(end = "\n")