这道题因为我把puzzle打成了Puzzle,卡了我很久…………真的太无语了。
题目链接如下:
我的代码如下:
- #include
- #include
- #include
- 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;
- }