栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ZCMU--2194: African Crossword(C语言)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ZCMU--2194: African Crossword(C语言)

Description

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 
char a[105][105];
int main()
{
	int n,m,i,s,x,shi;	//shi用来标记同一行列是否出现相同字母 
	while(~scanf("%d%d",&n,&m)){
		getchar();		//吃掉空格 
		for(i=1;i<=n;i++){
			for(s=1;s<=m;s++) scanf("%c",&a[i][s]);	//输入字母 
			getchar();	//吃掉空格 
		}
		for(i=1;i<=n;i++){		//先判断同一行 
			for(s=1;s<=m;s++){
				shi=0;		//判断是否出现相同字母 
				for(x=1;x<=m;x++){
					if(x!=s&&a[i][x]==a[i][s]){	//x!=s表示跳过本身位置,如果出现了相同字母 
						shi=1;	//标志为1 
						break;	//退出 
					}
				}
				if(shi==0){		//如果同一行没出现过相同字母,判断同一列		 
					for(x=1;x<=n;x++){
						if(x!=i&&a[x][s]==a[i][s]){		//与上同理 
							shi=1;
							break;
						}
					}
				}
				if(shi==0) printf("%c",a[i][s]); //如果行列都没出现,就满足,输出 
			}
		}
		printf("n");
}	
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/875644.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号