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;
}
相关推荐
小wanga25 分钟前
leetcode-hot100
算法·leetcode·职场和发展
完美的奶酪25 分钟前
Leetcode-930. 和相同的二元子数组
算法·leetcode
onlyzzr26 分钟前
备战秋招版 --- 第12题:85.最大矩形
算法
GG不是gg1 小时前
二分算法深度解析
算法
喵~来学编程啦2 小时前
【全队项目】从GAN到ESRGAN的超分辨率处理
开发语言·python·算法
机器学习之心2 小时前
光伏功率预测 | RF随机森林多变量单步光伏功率预测(Matlab完整源码和数据)
算法·随机森林·matlab·多变量单步光伏功率预测
倔强的石头_2 小时前
【数据结构与算法】归并排序:从理论到实践的深度剖析
后端·算法
小胖同学~2 小时前
插入排序C语言版
java·javascript·算法
倔强的石头_2 小时前
【数据结构与算法】快速排序万字全攻略:hoare版本、挖坑法、前后指针法、优化版、非递归实现
后端·算法
lishanlu1362 小时前
目标检测——YOLOv12算法解读
算法·yolo·目标检测