zcmu 2194: African Crossword

2194: African Crossword

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: 43  Solved: 36
[Submit][Status][Web Board]

Description

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

An African crossword is a rectangular table n×m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.

To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.

When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.

You are suggested to solve an African crossword and print the word encrypted there.

Input

The first line contains two integers n and m (1≤n,m≤100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Output

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

Examples

Input

3 3
cba
bcd
cbc

Output

abcd

Input

5 5
fcofd
ooedo
afaoa
rdcdf
eofsf

Output

codeforces

题意: 输入n,m,有一个n * m的字符阵,对于每行和每列,删去相同的字符,最后按顺序输出剩下的字符。

#include<bits/stdc++.h>
#define ll long long
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=100005;
const int maxn=1e6+5; 
int dp1[110][110],dp2[110][110];
char a[110][110];
int main(){
	int n,m;
	cin>>n>>m;
	pre(i,1,n)
	   pre(j,1,m)
	      cin>>a[i][j];//读入数据 
	pre(i,1,n)
	   pre(j,1,m)
	      if(dp1[i][j]!=1)
	         pre(k,j+1,m)
	            if(a[i][j]==a[i][k])
	                dp1[i][j]=dp1[i][k]=1;//标记 
	pre(i,1,m)
	   pre(j,1,n)
	      if(dp2[j][i]!=1)
	         pre(k,j+1,n)
	            if(a[j][i]==a[k][i])
                       dp2[j][i]=dp2[k][i]=1;
	pre(i,1,n)
	   pre(j,1,m)
	      if(dp1[i][j]!=1&&dp2[i][j]!=1)//判断是否删去 
	         cout<<a[i][j];
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值