poj 3923

#include<cstring>
#include<queue>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char Map[150][150];
int vis[150][150];
struct node
{
    char ch;
    int lx,ly;
    int rx,ry;
} point[150];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m),n||m)
    {
        int i,j,z;
        int top=0;
        getchar();
        for(i=1; i<=n; i++){
            for(j=1;j<=m;j++)
                scanf("%c",&Map[i][j]);
            getchar();
        }
        memset(vis,0,sizeof(vis));
        for(i=1; i<=n; i++)
            for(j=1; j<=m; j++) {
                if(vis[i][j]==0&&Map[i][j]!='.'){
                    char tch=Map[i][j];
                    int tempx=i,tempy=j;
                    int ty=tempy+1,tx=tempx+1;
                    int tty=tempy+1,ttx=tempx+1;
                    int lon[5];
                    for(z=1; z<=4; z++) lon[z]=0;
                    while(ty>=1&&ty<=m&&Map[tempx][ty]==tch){
                        vis[tempx][ty]=1;
                        ty++;
                        lon[1]++;
                    }
                    ty--;
                    while(tx>=1&&tx<=n&&Map[tx][tempy]==tch){
                    vis[tx][tempy]=1;
                        tx++;
                        lon[2]++;

                    }
                    tx--;
                    while(tty>=1&&tty<=m&&Map[tx][tty]==tch){
                    vis[tx][tty]=1;
                        tty++;
                        lon[3]++;

                    }
                    tty--;
                    while(ttx>=1&&ttx<=n&&Map[ttx][ty]==tch){
                    vis[ttx][ty]=1;
                        ttx++;
                        lon[4]++;
                    }
                    ttx--;
                    if(lon[2]==lon[4]&&lon[1]==lon[3]&&lon[2]>0&&lon[1]>0){
                        point[top].lx=tempx;
                        point[top].ly=tempy;
                        point[top].rx=ttx;
                        point[top].ry=tty;
                        point[top].ch=tch;
                        top++;
                    }
                }
                vis[i][j]=1;
            }
        char ans[150];
        int top1=0;
        int l[150],flag=0;
        memset(l,0,sizeof(l));
        for(i=0;i<top;i++){
            if(l[i]==0){
                flag=0;
                for(j=i+1;j<top;j++){
                    if(point[i].lx<point[j].lx&&point[i].ly<point[j].ly)
                        if(point[i].rx>point[j].rx&&point[i].ry>point[j].ry){
                            flag=1;
                        }
                }
                if(flag==0) ans[top1++]=point[i].ch;
          }
        }
        sort(ans,ans+top1);
        for(i=0;i<top1;i++) printf("%c",ans[i]);
        printf("\n");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值