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:
# https://atcoder.jp/contests/abc107/tasks/abc107_b

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

    a = [ai for ai in a if any(ais == '#' for ais in ai)]

    i = 0
    while i < len(a[0]):
        if all(ai[i] == '.' for ai in a):
            for ai in a:
                del ai[i]
        else:
            i += 1
            continue

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

initial_map = []
for i in res:
    row = [f for f in i]
    initial_map.append(row[0])

remove_list = []
for i in range(H):
    if '#' not in initial_map[i]:
        remove_list.append(i)

count = 0
for i in remove_list:
    initial_map.pop(i-count)
    count += 1

remove_list = []

initial_map_t = np.array(initial_map).T.tolist()

for i in range(W):
    if '#' not in initial_map_t[i]:
        remove_list.append(i)

count = 0
for i in remove_list:
    initial_map_t.pop(i-count)
    count += 1

res = np.array(initial_map_t).T.tolist()

for i in res:
    for j in i:
        print(j,end='')
    print()

Submission status: Accepted

Solution code:
def main() -> None:
    h, w = map(int, input().split())
    a = []
    for _ in range(h):
        a.append(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()


if __name__ == '__main__':
    main()

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 j in range(w - 1, -1, -1):
    for i in range(len(A)):
        if A[i][j] == '#':
            break
    else:
        for k in range(len(A)):
            del A[k][j]
            
for i in range(len(A)):
    print(''.join(A[i]))

Submission status: Accepted

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

e = [""] * h
for i in range(h):
    e[i] = input()
    

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



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

Submission status: Accepted

Solution code:
int_h, int_w = map(int, input().split())

masu = list()

for i in range(int_h):
    masu.append(list(input()))

conv = list()
for x in list(map(list, zip(*masu))):
    if "#" in x:
        conv.append(x)

result = list()

for y in list(map(list, zip(*conv))):
    if "#" in y:
        result.append(y)

for r in result:
    print("".join(r))

Submission status: Accepted

Solution code:
def main():
 h, w = map(int, input().split())
 a = [input() for _ in range(h)]
 na = []
 l = [0] * (w + 1)
 for i in range(h):
  if not("#" in a[i]):
   pass
  else:
   na += [a[i]]
   for j in range(w):
    if a[i][j] == "#":
     l[j] += 1
 for i in na:
  for j in range(w):
   if l[j] != 0:
    print(i[j], end="")
  print("")
main()

Submission status: Accepted

Solution code:
def func(A,H,W):
    H_del=[]
    W_del=[]
    for h in range(H):
        if A[h][0]=='.':
            g=1
            for w in range(1,W):
                if A[h][w]!='.':
                    g=0
                    break
            if g==1:
                H_del.append(h)
    for w in range(W):
        if A[0][w]=='.':
            g=1
            for h in range(1,H):
                if A[h][w]!='.':
                    g=0
                    break
            if g==1:
                W_del.append(w)
    return H_del,W_del

def show(A,H_del,W_del,H,W):
    for h in range(H):
        if h in H_del:
            continue
        for w in range(W):
            if w in W_del:
                continue
            print(A[h][w],end='')
        print('')
H,W=map(int,input().split())
A=[]
H_del=[]
W_del=[]
for i in range(H):
    A.append(list(input()))
H_del,W_del=func(A,H,W)
show(A,H_del,W_del,H,W)

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):
    char=''
    if row[i]:
        for j in range(w):
            if col[j]:
                char+=a[i][j]
            else:
                continue
    else:
        continue
    print(char)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [[0 if x == "." else 1 for x in input()] for _ in range(H)]
A = [a for a in A if sum(a) != 0]
W_cut = [w for w in range(W) if sum([a[w] for a in A]) == 0]
for a in A:
    line = ""
    for w in range(W):
        if w in W_cut:
            continue
        line += "." if a[w] == 0 else "#"
    print(line)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
a = []
for i in range(H):
    a_l = input()
    a.append([c for c in a_l])


for i in range(H):
    for j in range(W):
        if a[i][j] == '.':
            a[i][j] = 1
        elif a[i][j] == '#':
            a[i][j] = 0
        else:
            pass
a = np.array(a)
v = []
h = []
for i in range(H):
    if np.sum(a[i,:]) == W:
        h.append(i)
for j in range(W):
    if np.sum(a[:,j]) == H:
        v.append(j)

a_del = np.delete(np.delete(a, v, 1), h, 0)
a_del = list(a_del)

for i in range(len(a_del)):
    for j in range(len(a_del[i])):
        if a_del[i][j] == 1:
            print('.', end='')
        elif a_del[i][j] == 0:
            print('#', end='')
    print('')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
mx = []
for i in range(h):
    mx.append(list(map(str, input().split())))
for i in range(h-1,-1,-1):
    if not '#' in mx[i][0]:
        del mx[i]
l = []
for i in range(w):
    for j in range(len(mx)):
        if mx[j][0][i]=='#':
            break
        if j==len(mx)-1:
            l.append(i)
if l:
    for i in range(1,len(l)+1):
        for j in range(len(mx)):
            if l[-i]==len(mx[j][0])-1:
                mx[j][0]=mx[j][0][:l[-i]]
            else:
                mx[j][0]=mx[j][0][:l[-i]]+mx[j][0][l[-i]+1:]
for m in mx:
    print(m[0])

Submission status: Accepted

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

l = []

for i in range(H):
    l.append(input())

y = [False] * H
x = [False] * W

for i in range(H):
    flg = True
    for j in range(W):
        if l[i][j] != '.':
            flg = False
            break
    if flg:
        y[i] = True

for i in range(W):
    flg = True
    for j in range(H):
        if l[j][i] != '.':
            flg = False
            break
    if flg:
        x[i] = True

for i in range(H):
    if y[i]:
        continue
    for j in range(W):
        if x[j]:
            continue
        print(l[i][j], end='')
    print()

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [str(input().strip()) for _ in range(H)]
  B = []
  for i in range(len(A)):
    if A[i] != '.'*W:
      B.append([str(c) for c in A[i]])

  C = [[0 for _ in range(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]
  
  D = []
  for i in range(len(C)):
    if ''.join(C[i]) != '.' * len(C[0]):
      D.append([str(c) for c in C[i]])
  
  E = [[0 for _ in range(len(D))] for _ in range(len(D[0]))]
  for i in range(len(D)):
    for j in range(len(D[0])):
      E[j][i] = D[i][j]

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


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
# B
H, W = map(int, input().split())
a = []
for _ in range(H):
    i = list(input())
    if '#' in i:
        a.append(i)
ans = zip(*[i for i in zip(*a) if '#' in i])
for s in ans:
    print(*s, sep='')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
for i in range(h):
    if set(a[h-i-1]) == {'.'}:
        del(a[h-i-1])
for i in range(w):
    if set([j[w-i-1] for j in a]) == {"."}:
        for j in a:
            del(j[w-i-1])
for i in a:
    print(''.join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
maps = []
for i in range(h):
	maps.append(str(input()))
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if maps[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(maps[i][j], end = '')
		print()

Submission status: Accepted

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

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("\n")

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = [""] * H #空白のリスト
for i in range(H):
    a[i] = input()

row = [False] * H #真偽値の2次元配列
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 = [input() for _ in range(h)]
a = [x for x in a if not all([i == '.' for i in x])]
b = [[x[i] for x in a] for i in range(w)]
b = ["".join(x) for x in b]
b = [x for x in b if not all([i == '.' for i in x])]
c = [[x[i] for x in b] for i in range(len(b[0]))]
c = ["".join(x) for x in c]
print(*c, sep="\n")

Submission status: Accepted

Solution code:
import sys
def こたえ():
    H,W = [int(_) for _ in input().split()]
    aM = [_.rstrip() for _ in sys.stdin.readlines()]
    aH = [True]*H
    aW = [True]*W
    for i in range(H):
        bH = True
        for j in range(W):
            bW = True if aM[i][j] == "." else False
            if bH and not bW:
                bH = False
            if aW[j] and  not bW :
                aW[j]=False
        aH[i] = bH
    for i in range(H):
        if not aH[i]:
            for j in range(W):
                if not aW[j]:
                    sys.stdout.write(aM[i][j])
            sys.stdout.write("\n")
こたえ()

Submission status: Accepted

Solution code:
#除くではなくて除かなくていい部分を選ぶ→各文字で考えず行・列単位で考える
h,w = list(map(int,input().split()))
a = [""] * h

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

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

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
HW = [input() for _ in range(H)]
HW = [''.join(hw) for hw in zip(*HW) if hw.count('#') > 0]
HW = [''.join(hw) for hw in zip(*HW) if hw.count('#') > 0]
print('\n'.join(HW))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=[]
C=[]
for i in range(h):
    if (set(A[i]))!={'.'}:
        B.append(A[i])
B=list(map(list, zip(*B)))
h_=len(B)
for i in range(h_):
    if set(B[i])!={'.'}:
        C.append(B[i])
C=list(map(list, zip(*C)))
h__=len(C)
for i in range(h__):
    print(''.join(map(str,C[i])))

Submission status: Accepted

Solution code:
class Solver(object):
    def __init__(self):
        self.h, self.w = list(map(int, input().split(" ")))
        self.grid = [[] for _ in range(self.h)]  # grid[row][column]
        for row in range(self.h):
            for value in input():
                self.grid[row].append(value)

    def solve(self):
        for row in range(self.h):
            for column in range(self.w):
                if self.grid[row][column] == ".":
                    self.check_and_delete(row, column)
        self.print_grid()

    def check_and_delete(self, row, column):
        # row-wise
        delete = True
        for c in range(self.w):
            if self.grid[row][c] is not None:
                if self.grid[row][c] == "#":
                    delete = False
        if delete:
            for c in range(self.w):
                self.grid[row][c] = None

        # column-wise
        delete = True
        for r in range(self.h):
            if self.grid[r][column] is not None:
                if self.grid[r][column] == "#":
                    delete = False
        if delete:
            for r in range(self.h):
                self.grid[r][column] = None
    
    def print_grid(self):
        for row in self.grid:
            printed = False
            for column in row:
                if column is not None:
                    printed = True
                    print(column, end="")
            if printed:
                print()


if __name__ == "__main__":
    s = Solver()
    s.solve()

Submission status: Accepted

Solution code:
def del_row(lines):
    if not lines:
        return
    erasable = []
    for idx, line in enumerate(lines):
        if all([c == '.' for c in line]):
            erasable.append(idx)
    for idx in erasable[::-1]:
        del lines[idx]


def del_col(lines):
    if not lines:
        return
    erasable = []
    for idx in range(len(lines[0])):
        col = [lines[i][idx] for i in range(len(lines))]
        if all([c == '.' for c in col]):
            erasable.append(idx)
    for idx in erasable[::-1]:
        for i in range(len(lines)):
            del lines[i][idx]


lines = []
H, W = [int(x) for x in input().split()]
for i in range(H):
    lines.append(list(input()))

del_row(lines)
del_col(lines)
for line in lines:
    print(''.join(line))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

cells = []
for h in range(H):
    s = input()
    if s != '.' * W:
        cells.append(s)

new_cells = [''] * len(cells)
for w in range(W):
    delete = True
    for c in cells:
        if c[w] == '#':
            delete = False
    if not delete:
        for h, c in enumerate(cells):
            new_cells[h] += cells[h][w]

for c in new_cells:
    print(c)

Submission status: Accepted

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

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

h2 = len(A)
for j in range(w - 1, -1, -1):
    for i in range(h2):
        if A[i][j] == '#':
            break
        elif i == h2 - 1:
            for k in range(h2):
                del A[k][j]
            
for a in A:
    print(''.join(a))

Submission status: Accepted

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

A = []
for i in range(h):
    s = list(input())
    if '#' in s:
        A.append(s)
        
B = [[0] * w for i in range(len(A))]
for i in range(len(A)):
    for j in range(w):
        if A[i][j] == '#':
            B[i][j] += 1
            
C = [0] * w
for i in range(len(A)):
    for j in range(w):
        C[j] += B[i][j]
        
D = [[] for i in range(len(A))]
for i in range(len(A)):
    for j in range(w):
        if C[j] != 0:
            D[i].append(A[i][j])
            
for i in range(len(A)):
    print(''.join(D[i]))

Submission status: Accepted

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

aa = [input() for _ in range(h)]
aa_rm=[]
target_row=[]
for row,a in enumerate(aa):
    if a.count('.') < w:
        target_row.append(row)

target_col=[]
for iw in range(w):
    col=[]
    for ih in range(h):
        col.append(aa[ih][iw])
    # print(col)
    if col.count('.') < h:
        target_col.append(iw)

ans =[]
for row in target_row:
    s=""
    for col in target_col:
        s+=aa[row][col]
    ans.append(s)
for a in ans:
    print(a)

Submission status: Accepted

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

r = set()
for i in range(h):
    ok = True
    for j in range(w):
        if a[i][j] == '#':
            ok = False
            break
    else:
        if ok:
            r.add(i)
c = set()
for j in range(w):
    ok = True
    for i in range(h):
        if a[i][j] == '#':
            ok = False
            break
    else:
        if ok:
            c.add(j)
for i in range(h):
    tmp = ''
    if i in r:
        continue
    for j in range(w):
        if j in c:
            continue
        tmp += a[i][j]
    print(tmp)

Submission status: Accepted

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

b = []
for i in range(h):
    cnt = 0
    for j in range(w):
        if a[i][j] == '.':
            cnt += 1
            
    if cnt != w:
        b.append(a[i])

c = ['']*len(b) 
for i in range(len(b[0])):
    cnt = 0
    for j in range(len(b)):
        if b[j][i] == '.':
            cnt += 1
    
    if cnt != len(b):
        for j in range(len(b)):
            c[j] += b[j][i]

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

Submission status: Accepted

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

arr_all = []
arr_del = []
for i in range(h):
    arr_w = input()
    if list(set(arr_w)) == ["."]:
        continue
    else:
        arr_all.append(arr_w)
        arr_del.append([])


d = []

for i in range(w):
    for j in range(len(arr_all)):
        if arr_all[j][i] == ".":
            if j == w - 1:
                break
            else:
                continue
        else:
            d.append(i)
            break

for j in range(len(arr_all)):
    for i in d:
        arr_del[j] += arr_all[j][i]


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

Submission status: Accepted

Solution code:
h,w = (int(i) for i in 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:
import numpy as np
import copy

h, w = map(int,input().split())
lst = [input() for i in range(h)]

array = np.zeros((h,w))
for n, i in enumerate(lst):
    for m, j in enumerate(i):
        array[n][m] = 1if j == '#' else 0

while True:
    origin = copy.deepcopy(array)
    array = array[:, array.sum(axis=0) > 0]
    array = array[array.sum(axis=1)>0, :]
    if array.shape == origin.shape:
        break

for i in array:
    string = ''
    for j in i:
        string += '#' if j == 1 else '.'
    print(string)

Submission status: Accepted

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

for i in range(H):
  for j in range(W):
    if a[i][j] == '#':
      a_h[i] = True
      a_w[j] = True

for i in range(H):
  if a_h[i] == True:
    for j in range(W):
      if a_w[j] == True:
        print(a[i][j],end='')
    print()

Submission status: Accepted

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

tmp = []
for a in zip(*A):
  if(a.count("#") > 0):
    tmp.append("".join(a))
tmp2 = []
for t in zip(*tmp):
  if(t.count("#") > 0):
    tmp2.append("".join(t))
print("\n".join(tmp2))

Submission status: Accepted

Solution code:

def solve(h, w, a):
    rs = []
    for r in range(h):
        ok = True
        for c in range(w):
            if a[r][c] == "#":
                ok = False
                break
        if not ok:
            rs.append(r)
    cs = []
    for c in range(w):
        ok = True
        for r in range(h):
            if a[r][c] == "#":
                ok = False
                break
        if not ok:
            cs.append(c)
    res = "\n".join(map(lambda r: "".join(map(lambda c: a[r][c], cs)), rs))
    return res


h, w = map(int, raw_input().split())
a = []
for r in range(h):
    a.append(raw_input())

#print h, w

#print a
print solve(h, w, a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
l = ["."]*w
while l in a:
  a.remove(l)
  
for j in range(w):
    s = 0
    for m in a:
        if m[j]=="#":
            s = 1
            break
    if s == 0:
        for m in a:
            m[j]=""
for i in a:
    print("".join(i))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
ahw = [strlist for strlist in [[s for s in input()] for i in range(H)] if "#" in strlist]
tenti = []
for h in range(W):
   m =  [ah[h] for ah in ahw]
   if "#" in m:
       tenti.append(m)
for ahwnum in range(len(ahw)):
    print("".join([num[ahwnum] for num in tenti]))

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):
    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))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
HW = [input() for _ in range(H)]
#print(HW)
#黒がない行は削除して転置,*で文字列を一文字ずつに分解、joinで再結合
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
#転置した後の黒がない行（元の行列の列に対応する）は削除して転置（元の行列に戻る）
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
print("\n".join(HW))#改行を伴って結合

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
matrix=[list(map(str,input().split())) for i in range(H)]
count_delete_H=0
count_delete_W=0

for i in range(H):
  matrix[i-count_delete_H]=list(*matrix[i-count_delete_H])
  if(matrix[i-count_delete_H].count('#')==0):
    del matrix[i-count_delete_H]
    count_delete_H+=1
    
matrix_t = [list(x) for x in zip(*matrix)]
for i in range(W):
  if(matrix_t[i-count_delete_W].count('#')==0):
    del matrix_t[i-count_delete_W]
    count_delete_W+=1
    
matrix_tt = [list(x) for x in zip(*matrix_t)]
for i in range(H-count_delete_H):
  for j in range(W-count_delete_W):
    print(matrix_tt[i][j],end='')
  print('')

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
matrix=[list(map(str,input().split())) for i in range(H)]
count_delete_H=0 #消した数を記憶しておく
count_delete_W=0 #同上

for i in range(H):
  matrix[i-count_delete_H]=list(*matrix[i-count_delete_H])#要素の文字列を1文字ごとに分解
  #print(matrix[i-count_delete_H].count('#'))
  if(matrix[i-count_delete_H].count('#')==0):
    del matrix[i-count_delete_H]
    count_delete_H+=1
    
matrix_t = [list(x) for x in zip(*matrix)]#転置をとる。
for i in range(W):
  #print(matrix_t[i-count_delete_W].count('#'))
  if(matrix_t[i-count_delete_W].count('#')==0):
    del matrix_t[i-count_delete_W]
    count_delete_W+=1
    
matrix_tt = [list(x) for x in zip(*matrix_t)]#転置をとって元に戻す。
#print(matrix_tt)
for i in range(H-count_delete_H):
  for j in range(W-count_delete_W):
    print(matrix_tt[i][j],end='')
  print('')#改行

Submission status: Accepted

Solution code:
""" AtCoder """

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

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

ans = []
ans = []
ans_len = 0

for i in range(H):
    if a[i].count('#') != 0:
        ans.append(a[i])
        ans_len += 1

for t in range(W):
    for i in range(W):
        check = True
        for j in range(ans_len):
            if ans[j][i] == '#':
                check = False
                break
        if check:
            tmp = ans
            ans = []
            for j in range(ans_len):
                ans.append(tmp[j][:i] + tmp[j][i+1:])
            W -= 1
            break

for i in range(ans_len):
    print(ans[i])

Submission status: Accepted

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

def main():
    h, w = map(int, input().split())
    rows = [input() for i in range(h)]
    rows = filter(rows)
    cols = transpose(rows)
    cols = filter(cols)
    rows = transpose(cols)
    for r in rows:
        print("".join(r))

def transpose(rows):
    h = len(rows)
    w = len(rows[0])
    cols = [[rows[i][j] for i in range(h)] for j in range(w)]
    return cols

def filter(rows):
    rows = [r for r in rows if "#" in r]
    return rows

main()

Submission status: Accepted

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


count = 0
for i in range(h-1,-1,-1):
  if "#" not in a[i]:
    del a[i]
    count +=1
h -=count

tenti_a = list(map(list, zip(*a)))
count = 0
for i in range(w-1,-1,-1):
  if "#" not in tenti_a[i]:
    del tenti_a[i]
    count +=1
w -=count

tenti_tenti_a = list(map(list, zip(*tenti_a)))
for i in range(h):
  print(str(tenti_tenti_a[i]).replace("[","").replace("]","").replace(",","").replace("'","").replace(" ",""))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
H, W = map(int, input().split(' '));

board = []
flags = [ True for x in range(W)]
for i in range(H):
    line = list(input())
    if ( '#' in line ):
        board.append(line)
        flags = [ f and s == '.' for s,f in zip(line, flags) ]

j = 0
for b in board:
    for l,flag in zip(b,flags):
        if not flag:
            sys.stdout.write(l)
    print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
s=[]
for _ in range(h):
    a = input() 
    if "#" in a:
        s.append(a)
d = []
for i in zip(*s):
    if "#" in i:
        d.append(i)
for j in zip(*d):
    print(*j,sep="")

Submission status: Accepted

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

matrix = []

for i in range(H):
  matrix.append(list(input()))

white = ['.'] * W

pop_list = []
counter = 0

i = H - 1
while i >= 0:
  if matrix[i] == white:
    matrix.pop(i)
    counter += 1
  i -= 1

white = ['.'] * (H - counter)
i = W - 1
 
while i >= 0:
  current_col = [r[i] for r in matrix]
  if current_col == white:
    for j, r in enumerate(matrix):
      matrix[j].pop(i)
  i -= 1

for r in matrix:
  for rr in r:
    print(rr, end = '')
  print('\n')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[]
for i in range(h):
  l.append(input())
a=[]
for i in range(h):
  if list(set(l[i]))!=list('.'):
    a.append(l[i])
for i in range(w):
  c=True
  for j in range(len(a)):
    if a[j][i]=='#':
      c=False
  if c:
    for j in range(len(a)):
      a[j]=a[j][:i]+'a'+a[j][i+1:]
    w-=1
for i in range(len(a)):
  a[i]=a[i].replace('a','')
for i in range(len(a)):
  print(a[i])

Submission status: Accepted

Solution code:
def main():
    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] is True:
            for j in range(W):
                if col[j] is True:
                    print(a[i][j], end='')
            print()


main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    A = list(map(str,input().split()))
    a.append(A)
kesu = []
for i in range(h):
    b = str(a[i])
    ten = 0
    for l in range(w):
        if b[l+2] == ".":
           ten += 1
    if w == ten :
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    a.pop(K-i)
hi = []
for i in range(w):
    hkari = ""
    for l in range(len(a)):
        h = str(a[l])
        hz = str(h[i+2])
        hkari += str(hz)
    hi.append(hkari)
kesu = []
for i in range(len(hi)):
    b = str(hi[i])
    ten = 0
    for l in range(len(b)):
        if b[l] == ".":
            ten += 1
    if len(b) == ten:
        kesu.append(i)
for i in range(len(kesu)):
    K = int(kesu[i])
    hi.pop(K-i)
b = len(str(hi[0]))
ans = []
for i in range(b):
    hkari = ""
    for l in range(len(hi)):
        h = str(hi[l])
        hz = str(h[i])
        hkari += str(hz)
    ans.append(hkari)
for i  in range(len(ans)):
    print(ans[i])

Submission status: Accepted

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

def main():
    na = list(map(int, input().split()))
    H, W = na[0], na[1]

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

    b = [0] * W
    for s in a:
        for i in range(W):
            if s[i] == '#':
                b[i] = 1

    for s in a:
        ss = ''
        for i in range(W):
            if b[i] == 1:
                ss += s[i]
        print(ss)


if __name__ == '__main__':
    main()