The football foundation (FOFO) has been researching on soccer; they created a set of sensors to describe the ball behavior based on a grid uniformly distributed on the field. They found that they could predict the ball movements based on historical analysis. Each square sensor of the grid can detect the following patterns:

N  north (up the field) S  south (south the field) E  east (to the right on the field) W  west (to the left on the field)

For example, in grid 1, suppose the ball was thrown into the field from north side into the field. The path the sensors detected for this movement follows as shown. The ball went through 10 sensors before leaving the field.

Comparing with what happened on grid 2, the ball went through 3 sensors only once, and started a loop through 8 instructions and never exits the field.

You are selected to write a program in order to evaluate line judges job, with the following out put based on each grid of sensors, the program needs to determine how long it takes to the ball to get out of the grid or how the ball loops around.

Input

There will be one or more grids of sensors for the same game. The data for each is in the following form. On the first line are three integers separated by blanks: The number of rows in the grid, the number of columns in the grid, and the number of the column in which the ball enters from the north. The grid column's number starts with one at the left. Then come the rows of direction instructions. The lines of instructions contain only the characters NSE or W, with no blanks. The end of input is indicated by a grid containing 0 0 0 as limits.

Output

For each grid in the input there is one line of output. Either the ball follows a certain number of sensors and exits the field on any one of the four sides or else the ball follows the behavior on some number of sensors repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word "step" is always immediately followed by "(s)" whether or not the number before is 1.

Sample Input

3 6 5
NEESWE
WWWESS
SNWWWW
4 5 1
SESWE
EESNW
NWEEN
EWSEN
0 0 0

Sample Output

10 step(s) to exit
3 step(s) before a loop of 8 step(s)
#include <iostream>
using namespace std; int main()
{
int row, col, num;
while (cin>>row>>col>>num)//&&(row!=0&&col!=0)
{
if(row==||col==||num==)
break;
char array[][];
int s[][]={};//初始化
for(int i = ;i < row; i++)
{
for(int j = ; j < col; j++)
cin >> array[i][j];
} int m = ;
s[m][num-]=;
int k = *col*row;//为了防止无限制循环下去
while(k--)
{
switch (array[m][num-])
{
case 'N' :
{
if (m!=)
{
m--;
s[m][num-] = s[m][num-]+; } break;
}
case 'S' :
{
if (m!=(row-))
{
m++;
s[m][num-] = s[m][num-]+; } break;
}
case 'W' :
{
if ((num-)!=)
{
num--;
s[m][num-] = s[m][num-]+; } break;
}
case 'E' :
{
if ((num-)!=(col-))
{
num++;
s[m][num-] = s[m][num-]+; } break;
}
}
}
int c=,d=;
for(int i = ;i<row;i++)
{ for (int j = ;j <col;j++)
{
if(s[i][j]==)
c++;
else if(s[i][j]>)
d++;
}
}
if(d==)
cout << c << " step(s) to exit" << endl;
else
cout << c << " step(s) before a loop of " << d << " step(s)"<< endl;
}
return ;
}

Football Foundation (FOFO) TOJ 2556的更多相关文章

  1. Foundation框架下的常用类:NSNumber、NSDate、NSCalendar、NSDateFormatter、NSNull、NSKeyedArchiver

    ========================== Foundation框架下的常用类 ========================== 一.[NSNumber] [注]像int.float.c ...

  2. POCO库——Foundation组件之核心Core

    核心Core: Version.h:版本控制信息,宏POCO_VERSION,值格式采用0xAABBCCDD,分别代表主版本.次版本.补丁版本.预发布版本: Poco.h:简单地包含了头文件Found ...

  3. POCO库——Foundation组件概述

    Foundation组件作为POCO库的基础组件,主要包含了核心Core.缓存Cache.加解密Crypt.日期时间DateTime.动态类型Dynamic.事件events.文件系统Filesyst ...

  4. iOS开发系列—Objective-C之Foundation框架

    概述 我们前面的章节中就一直新建Cocoa Class,那么Cocoa到底是什么,它和我们前面以及后面要讲的内容到底有什么关系呢?Objective-C开发中经常用到NSObject,那么这个对象到底 ...

  5. Introduction of OpenCascade Foundation Classes

    Introduction of OpenCascade Foundation Classes Open CASCADE基础类简介 eryar@163.com 一.简介 1. 基础类概述 Foundat ...

  6. IOS开发之学习《AV Foundation 开发秘籍》

    敲了这么久的代码,查阅了很多资料,都是网络电子版的,而且时间久了眼睛也累了,还不如看一下纸质的书籍,让眼睛休息休息. 本篇开始学习<AV Foundation 开发秘籍>,并记录对自己本人 ...

  7. diff/merge configuration in Team Foundation - common Command and Argument values - MSDN Blogs

    One of the extensibility points we have in Team Foundation V1 is that you can configure any other di ...

  8. 测试环境搭建心得 vs2008+SQL2008 PHP+APACHE+mysql Team Foundation Server2013

    大四即将结束,大学的最后一个假期,找到一份实习工作,担任测试工程师.在过年前的最后一周入职,干了一周的活儿.主要工作就是搭建测试环境. VMware 主要熟悉VMware软件,装系统基本都没什么问题. ...

  9. CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(1)设定背景图

    技术的新发展,除计算机可以接入互联网之外,平板电脑.智能手机.智能电视等其他设备均可访问互联网.在多设备时代,构建多屏体验也不是听说的那么难. 但是这也增加了学习CSS的难度?不知道如何上手,只懂一点 ...

随机推荐

  1. php修改指定文件的指定内容

    <?php $origin_str = file_get_contents('路径/文件.txt'); $update_str = str_replace('qwe=0', 'qwe=1', $ ...

  2. 上传读取Excel文件数据

    /// <summary> /// 上传读取Excel文件数据 /// 来自http://www.cnblogs.com/cielwater /// </summary> // ...

  3. (转)MySQL优化实例

    在Apache, PHP,MySQL的体系架构中,MySQL对于性能的影响最大,也是关键的核心部分.对于Discuz!论坛程序也是如此,MySQL的设置是否合理优化,直接影响到论坛的速度和承载量!同时 ...

  4. 杭电ACM 1013 Digital Root

    #include<stdio.h>#include<stdlib.h>#include<string.h>int main(){char s[100000];int ...

  5. jquery选择伪元素属性的方法

    CSS伪元素不是DOM元素,因此你无法直接选择到它们 一个方法是为该元素添加新类,并通过设置新类的属性来达到改变伪元素属性的效果: .checkboxWrapper.selected::before{ ...

  6. Google Chrome浏览器中如何使用命令

    Google Chrome浏览器中如何使用命令 | 浏览:2974 | 更新:2014-02-23 23:12 | 标签:chrome 1 2 3 分步阅读 Google Chrome浏览器有很多的特 ...

  7. IIS7下的伪静态配置

    某个项目是PHP的,本地是Apache + PHP + MYSQL,服务器上的环境是IIS + PHP + MYSQL,开发完成准备部署到服务器上发现伪静态无法使用,原因是IIS不能解析.htacce ...

  8. book

    http://www.ed2000.com/ShowFile.asp?FileID=61391 e-itbook.com

  9. 【axc】简单的线性动画绘制

    在一个View上绘制一条直线  然后做出相应的动画效果  可以这样封装三个方法: /** *  划线工具 * *  @param lineArray   线段的点数组 NSValue 类型  默认第一 ...

  10. iOS开发之音频口通信-通过方波来收发数据

    之前做过的项目有需要通过音频口通信用方波来收发数据,由于这方面的资料比较少,下面就介绍下其原理,希望能给大家帮助. 一. 音频通信简介大家应该都知道支付宝声波支付和拉卡拉吧,它们都是利用手机的音频口( ...