Codeforces 90B-African Crossword

African Crossword
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
题意:给定一个字符矩阵,对于某个字符如果在同行或者同列有相同的字符出现,那么这个字符被标记,最后从上到下、从左到右输出所有未标记字符。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

char ch[105][105];
int visit[105][105];
int n,m;

int check(int x,int y)
{
    int flag=0;
    for(int i=0;i<n;i++)
        if(i!=x&&ch[x][y]==ch[i][y]) visit[i][y]=1,flag=1;
    for(int i=0;i<m;i++)
        if(i!=y&&ch[x][y]==ch[x][i]) visit[x][i]=1,flag=1;
    return flag;
}

int main()
{
    while(~scanf("%d %d",&n,&m))
    {
        memset(visit,0,sizeof visit);
        for(int i=0;i<n;i++)
            scanf("%s",ch[i]);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                int ans=check(i,j);
                if(ans) visit[i][j]=1;
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
                if(!visit[i][j]) printf("%c",ch[i][j]);
        }
        printf("\n");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值