CodeForces 90B African Crossword【模拟】
2016-10-22 17:13
281 查看
African Crossword
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces
90B
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.
Sample Input
Input
Output
Input
Output
codeforces
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
const int INF=0x7ffffff;
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
const int M=100+1;
char mp[M][M];
int flag[M][M];
int i,j,k,n,m;
void cheak(int nn,int mm)
{
for(int k=nn+1;k<n;k++){
if(mp[k][mm]==mp[nn][mm])
flag[k][mm]++,flag[nn][mm]++;
}
for(int k=mm+1;k<m;k++){
if(mp[nn][k]==mp[nn][mm])
flag[nn][k]++,flag[nn][mm]++;
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
MS(flag,0);
for(int i=0;i<n;i++)
scanf("%s",mp[i]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
cheak(i,j);
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(!flag[i][j])printf("%c",mp[i][j]);
printf("\n");
return 0;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces
90B
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.
Sample Input
Input
3 3 cba bcd cbc
Output
abcd
Input
5 5 fcofd ooedo afaoa rdcdf eofsf
Output
codeforces
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
const int INF=0x7ffffff;
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
const int M=100+1;
char mp[M][M];
int flag[M][M];
int i,j,k,n,m;
void cheak(int nn,int mm)
{
for(int k=nn+1;k<n;k++){
if(mp[k][mm]==mp[nn][mm])
flag[k][mm]++,flag[nn][mm]++;
}
for(int k=mm+1;k<m;k++){
if(mp[nn][k]==mp[nn][mm])
flag[nn][k]++,flag[nn][mm]++;
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
MS(flag,0);
for(int i=0;i<n;i++)
scanf("%s",mp[i]);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
cheak(i,j);
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(!flag[i][j])printf("%c",mp[i][j]);
printf("\n");
return 0;
}
相关文章推荐
- codeforces-#475A. Bayan Bus(模拟)
- Codeforces 67A【模拟】
- CodeForces 686A Free Ice Cream (水题模拟)
- 【CodeForces 651A】Joysticks 模拟
- CodeForces 342B Xenia and Spies (水题模拟,贪心)
- Codeforces 400C Inna and Huge Candy Matrix(模拟)
- Codeforces 379C New Year Ratings Change(模拟)
- Codeforces 549A. Face Detection[模拟]
- Codeforces 2A: Winner【STL】【模拟】
- Codeforces-691C-Exponential notation(模拟)
- codeforces 591C (模拟)
- Codeforces 659B Qualifying Contest 【模拟】
- Codeforces - 831A. Unimodal Array - 模拟
- CodeForces 644B【模拟】
- CodeForces - 796B 模拟
- Codeforces 863C 模拟
- 【模拟】【codeforces】451B Sort the Array
- codeforces 722系列ABCD 【套题】模拟+并查集+STL+数学二分
- CodeForces 723B Text Document Analysis (水题模拟)
- 【Codeforces 723B】Text Document Analysis 模拟