UVA 232 Crossword Answers

题目描述

链接:https://odzkskevi.qnssl.com/963433dd82c52cf702fde21457b672c9?v=1508485620


题意,讲道理,我到现在也没看懂这一片英文,很尴尬,就在猜,隐约看到了从左往右,从上往下,以*或者到边界了,就算分割开,然后再猜他那个每一个字符串的标号怎么来的,竟然还有一样的,观察发现,如果在ij为起始点,那么如果横竖都有符合条件的他俩的标号都是一样的

My ugly code

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int r,c;
char a[15][15];
int b[15][15];
int cas=1;

int main(){

    while(~scanf("%d",&r) && r){
        scanf("%d",&c);
        map<int,string> acr;
        map<int,string> dow;
        for(int i=1;i<=r;i++){
            scanf("%s",a[i]+1);
        }
        memset(b,0,sizeof(b));
        for(int i=1;i<=r;i++){
            for(int j=1;j<=c;j++){
                if(a[i][j]=='*'){
                    b[i][j]=-1;
                }
            }
        }
        int cnt=1;
        for(int i=1;i<=r;i++){
            for(int j=1;j<=c;j++){
                if(b[i][j]==-1)
                    continue ;
                int flag=0;
                if(j-1 == 0 || b[i][j-1]==-1){
                    int k=j;
                    string s1="";

                    flag=1;
                    while(b[i][k]!=-1 && k <= c){
                        s1+=a[i][k++];
                    }
                    s1+='\0';
                    acr[cnt]=s1;
                }
                if(i-1 == 0 || b[i-1][j]==-1){
                    int k=i;
                    string s1="";
                    flag=1;
                    while(b[k][j]!=-1 && k <= r){
                        s1+=a[k++][j];
                    }
                    s1+='\0';
                    dow[cnt]=s1;
                }

                if(flag) cnt++;
            }
        }
        if(cas > 1) printf("\n");
        printf("puzzle #%d:\n",cas++);
        printf("Across\n");
        //printf("%d\n",acr.size());
        map<int,string>::iterator itor;
        for(itor=acr.begin();itor!=acr.end();itor++){
            int ans1;
            string ans2;
            ans1=itor->first;
            ans2=itor->second;
            printf("%3d.%s\n",ans1,ans2.c_str());

        }
        printf("Down\n");
        map<int,string>::iterator itor1;
        for(itor1=dow.begin();itor1!=dow.end();itor1++){
            int ans1=itor1->first;
            string ans2=itor1->second;
            printf("%3d.%s\n",ans1,ans2.c_str());
        }

    }


    return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值