CUC-SUMMER-6-H

H - African Crossword
CodeForces - 90B

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.

Example
Input
3 3
cba
bcd
cbc
Output
abcd
Input
5 5
fcofd
ooedo
afaoa
rdcdf
eofsf
Output
codeforces


题意:解码,去掉一行和一列中重复字母,剩下的字母为答案。

解法:暴力,枚举每一个元素,对其同行同列的数遍历,去掉相同的数。

代码:

#include<iostream>
using namespace std;
char a[101][101];
int b[101][101]={0,};
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            for(int k=j+1;k<m;k++)
                if(a[i][j]==a[i][k]){
                    b[i][j]=1;
                    b[i][k]=1;
                    break;
                }
            for(int k=i+1;k<n;k++)
                if(a[i][j]==a[k][j]){
                    b[i][j]=1;
                    b[k][j]=1;
                    break;
                }
            if(b[i][j]==1)
                continue;
            cout<<a[i][j];
        }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,475评论 0 23
  • 网络上有很多登出的高校书单,而对比国际知名高校与国内高校的书单,却可以发现有趣的现象。 纵观推荐的书单,外国高校阅...
    青争志阅读 5,247评论 3 10
  • 上期我们说到几种反弹最常见的表现,其中最多的就是快速瘦身反弹。快速瘦身的方法市面上太多了,但是能够保持的确很少,就...
    享瘦健康阅读 4,795评论 0 0
  • 原来,我们都不曾满足: 人在地球上的所作所为,实在没有太多令人自豪。 虽然我们主宰了环境、增加了粮食产量盖起城市建...
    马唐阅读 903评论 0 0
  • 何为清歡?红尘客满目繁华皆俗世,找不到一丝乐趣,忙忙碌碌皆非所愿愿非所得。 人间烟火须臾数年,无知...
    空城锦阅读 1,573评论 0 0