232 - Crossword Answers (UVA)

这道题因为我把puzzle打成了Puzzle,卡了我很久............真的太无语了。

题目链接如下:

Online Judge

我的代码如下:

cpp 复制代码
#include <cstdio>
#include <cctype>
#include <set>
const int maxx = 10;

int r, c, kase, cnt, temp;
char a[maxx][maxx];
int num[maxx][maxx];

int main(){
    kase = 0;
    while(scanf("%d", &r) == 1 && r){
        scanf("%d", &c);
        getchar();
        cnt = 0;
        for(int i = 0; i < r; ++i){
            for(int j = 0; j < c; ++j){
                scanf("%c", &a[i][j]);
                if(isalpha(a[i][j]) && (i == 0 || j == 0 || a[i - 1][j] == '*' || a[i][j - 1] == '*')){
                    num[i][j] = ++cnt;
                } else{
                    num[i][j] = -1;
                }
            }
            getchar();
        }
        printf("%s", 0 == kase ? "" : "\n");
        printf("puzzle #%d:\nAcross\n", ++kase);
        for(int i = 0; i < r; ++i){
            for(int j = 0; j < c; ++j){
                if(isalpha(a[i][j])){
                    printf("%3d.", num[i][j]);
                    while(j < c && isalpha(a[i][j])){
                        printf("%c", a[i][j]);
                        ++j;
                    }
                    printf("\n");
                }
            }
        }
        printf("Down\n");
        std::set<int> st;
        for(int j = 0; j < c; ++j){
            for(int i = 0; i < r; ++i){
                if(isalpha(a[i][j])){
                    st.insert(num[i][j]);
                    while(i < r && isalpha(a[i][j])){
                        ++i;
                    }
                }
            }
        }
        for(int i = 0; i < r; ++i){
            for(int j = 0; j < c; ++j){
                if(st.find(num[i][j]) != st.end()){
                    printf("%3d.", num[i][j]);
                    temp = i;
                    while(temp < r && isalpha(a[temp][j])){
                        printf("%c", a[temp][j]);
                        ++temp;
                    }
                    printf("\n");
                }
            }
        }
    }
    return 0;
}
相关推荐
郑州光合科技余经理7 小时前
代驾系统架构拆解:订单链路、权限组织与私有化源码交付
开发语言·后端·算法·架构·系统架构·uni-app·php
To_OC9 小时前
LC 35 搜索插入位置:二分查找谁都会,边界条件谁写谁懵
javascript·算法·leetcode
码哥DFS10 小时前
二叉树的直径
开发语言·javascript·算法
营养充电站12 小时前
KMP全栈开发:从Android到AI Agent的技术演进与实践
人工智能·算法·docker·jupyter
技术小黑13 小时前
RNN算法实战系列05 | 天气预测
人工智能·rnn·算法
Ivanqhz16 小时前
php8 use-def链
算法·php
evans在进步16 小时前
LeetCode 189 轮转数组:三次反转原地解决,图解 Java 实现
java·算法·leetcode
歌_顿16 小时前
Drawing_To_Model
算法
龍德明宇16 小时前
AI不会疼-龍德明宇
人工智能·算法·大语言模型llm·负主体性·ai存在论