题目:https://www.luogu.com.cn/problem/UVA232
看题目直接点链接
。。想了好多办法结果都有问题,在这张的题里面主要用数组,,思维太差了。。
#include<iostream>
#include<cstring>
using namespace std;
int r,c,count=1,t,i,j,k,pr;
char g[11][11];
int p[11][11];
int main(){
while(scanf("%d",&r) && r!=0){
scanf("%d",&c);
t = 0;
if(count>1) putchar('\n');
printf("puzzle #%d:\nAcross\n",count++);
for(i = 0;i<r;i++){
scanf("%s",g[i]);
pr = 0;
for(j = 0;j<c;j++){
if(g[i][j] == '*') continue;
if(i == 0 || g[i-1][j] == '*' || j == 0 || g[i][j-1] == '*')
t++;p[i][j] = t;
if(j>=pr){
printf("%3d.",t);
for(k = j;k<c&&g[i][k]!='*';k++){
putchar(g[i][k]);
}
pr = k+1;
putchar('\n');
}
}
}
printf("Down\n");
for(i = 0;i<r;i++){
for(j = 0;j<c;j++){
if(!p[i][j]) continue;
printf("%3d.",p[i][j]);
for(k = i;k<r&&g[k][j] != '*';k++){
p[k][j] = 0;
putchar(g[k][j]);
}
putchar('\n');
}
}
}
return 0;
}
|