zoukankan      html  css  js  c++  java
  • poj1573

    简单题

    View Code
    //zoj1708
    #include <iostream>
    using namespace std;
    
    const    int        maxn = 11;
    
    char    order[maxn][maxn];
    int        steps[maxn][maxn], n, m, start;
    
    void init()
    {
        int        i, j;
        
        memset(steps, 0, sizeof(steps));
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                cin >> order[i][j];
    }
    
    void work()
    {
        int        x, y, now;
        
        x = 0;
        y = start - 1;
        now = 1;
        steps[x][y] = now;
        while (1)
        {
            switch (order[x][y])
            {
                case    'N':x--;break;
                case    'W':y--;break;
                case    'S':x++;break;
                case    'E':y++;break;
            }
            if (x < 0 || x >= n || y < 0 || y >= m)
            {
                cout << now << " step(s) to exit\n";
                return;
            }
            now++;
            if (steps[x][y] != 0)
            {
                cout << steps[x][y] - 1 << " step(s) before a loop of " << now - steps[x][y] << " step(s)\n";
                return;
            }
            steps[x][y] = now;
        }
    }
    
    int main()
    {
        //freopen("t.txt", "r", stdin);
        cin >> n >> m >> start;
        while (!(n == 0 && m == 0 && start == 0))
        {
            init();
            work();
            cin >> n >> m >> start;
        }
        return 0;
    }
  • 相关阅读:
    写一个含数字,拼音,汉字的验证码生成类
    Vue.js 学习示例
    webapi
    webapi
    WebApi接口
    WebApi接口
    WebApi
    个人插件锦集
    ShenNiu.MVC管理系统
    Centos6搭建Samba服务并使用Windows挂载
  • 原文地址:https://www.cnblogs.com/rainydays/p/2983139.html
Copyright © 2011-2022 走看看