zoukankan      html  css  js  c++  java
  • poj1573

    以前貌似做过这个题 WA2次 一次因为复制输出的时候 把8复制上去了 还有理解错了 以为小于等于1的时候要去S呢

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     int n, m, t, i, j, k,num,a[12][12],x,y,count1,count2;
     6     char c[11][11];
     7     while(scanf("%d%d%d%*c", &n, &m, &t)&&n&&m&&t)
     8     {
     9         num = 0;
    10         int flag = 0;
    11         k = 0;
    12         memset(a,0,sizeof(a));
    13         for(i = 1 ; i <= n ; i++)
    14         {
    15             for(j = 1 ; j <= m ;j++)
    16                 scanf("%c", &c[i][j]);
    17             getchar();
    18         }
    19         x = 1;
    20         y = t;
    21         while(x>0&&x<=n&&y>0&&y<=m)
    22         {
    23             a[x][y]++;
    24             if(k==0&&a[x][y] == 2)
    25             {
    26                 count1 = num;
    27                 k = 1;
    28             }
    29             if(a[x][y] == 3)
    30             {
    31                 count2 = num-count1;
    32                 count1 = count1-count2;
    33                 flag = 1;
    34                 break;
    35             }
    36             switch(c[x][y])
    37             {
    38             case 'N':x--;break;
    39             case 'S':x++;break;
    40             case 'E':y++;break;
    41             case 'W':y--;break;
    42             }
    43             num++;        
    44         }
    45         if(!flag)
    46         {
    47             printf("%d step(s) to exit\n",num);
    48         }
    49         else
    50         {        
    51             printf("%d step(s) before a loop of %d step(s)\n",count1,count2);
    52         }
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    Python_异常处理
    Python_文件相关操作
    Python_集合
    Python_字典
    Python_元组
    Python_列表操作2
    Python_列表操作1
    Spring-Data-Jpa使用总结
    SpringBoot源码分析之---SpringBoot项目启动类SpringApplication浅析
    RESTful API批量操作的实现
  • 原文地址:https://www.cnblogs.com/shangyu/p/2592719.html
Copyright © 2011-2022 走看看