zoukankan      html  css  js  c++  java
  • Crosswor Answers,(UVa, 232)

    Emmm....第一篇博客。

    打算要把《算法竞赛-入门经典(2版)》所有题刷一遍写题解,做评注。

    题目链接:https://vjudge.net/problem/UVA-232

     1 #include<stdio.h>
     2 #include<string.h>
     3 #define maxn 20
     4 char map[maxn][maxn];
     5 
     6 int main()
     7 {
     8     int r,c,count = 1;
     9     while(1)
    10     {
    11         int point = 1;
    12         scanf("%d",&r);
    13         if(r==0)
    14         break;
    15         else if(count > 1)
    16         printf("
    ");    
    17         int s[20][20] = {0};
    18         //memset(s,0,sizeof(s));
    19         scanf("%d",&c);
    20         getchar();
    21         for (int i = 0;i < r;i++ )
    22         {
    23             for (int j = 0;j < c;j++ )
    24             {
    25                 scanf("%c",&map[i][j]);
    26             }
    27             getchar();
    28             
    29         }
    30         for (int i = 0;i < r;i++ )
    31         {
    32             for (int j = 0;j < c;j++ )
    33             {
    34                 if((i==0||j==0||map[i][j-1] == '*'||map[i-1][j] == '*') && map[i][j] != '*')
    35                     s[i][j] = point++;
    36             }
    37         }
    38         printf("puzzle #%d:
    ",count++);
    39         printf("Across
    ");
    40         for (int i = 0;i < r;i++ )
    41         {
    42             
    43             for (int j = 0;j < c;j++ )
    44             {
    45                 int flag = 0;
    46                 if(s[i][j] != 0)
    47                 {
    48                     flag = 1;
    49                     printf("%3d.",s[i][j]);
    50                     for (;j < c&&map[i][j] != '*';j++)
    51                     printf("%c",map[i][j]);
    52                 }
    53                 if(flag)
    54                 printf("
    ");
    55             }
    56             
    57             
    58         }    
    59         printf("Down
    ");
    60         for (int i = 0;i < r;i++ )
    61         {
    62             
    63             for (int j = 0;j < c;j++ )
    64             {
    65                 int flag = 0;
    66                 if(s[i][j] != 0)
    67                 {
    68                     flag = 1;
    69                     printf("%3d.",s[i][j]);
    70                     for(int x = i;x < r&&map[x][j] != '*';x++)
    71                     {
    72                         s[x][j] = 0;
    73                         printf("%c",map[x][j]);
    74                     }
    75                 }
    76                 if(flag)
    77                 printf("
    ");
    78             }
    79         
    80             
    81         }    
    82         
    83         
    84     }
    85     return 0;
    86 }
  • 相关阅读:
    【leetcode】525. Contiguous Array
    【leetcode】827. Making A Large Island
    【leetcode】540. Single Element in a Sorted Array
    【leetcode】45. Jump Game II
    2017.11.2 Talk to customers for an hour
    New Concept English three (29)
    New Concept English three (28)
    2017.10.31 Enginer+position+statement
    New Concept English three (27)
    2017.10.30 Epicor -ERP
  • 原文地址:https://www.cnblogs.com/Dicer/p/8426842.html
Copyright © 2011-2022 走看看