Football Foundation (FOFO) TOJ 2556
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 N, S, E 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的更多相关文章
- Foundation框架下的常用类:NSNumber、NSDate、NSCalendar、NSDateFormatter、NSNull、NSKeyedArchiver
========================== Foundation框架下的常用类 ========================== 一.[NSNumber] [注]像int.float.c ...
- POCO库——Foundation组件之核心Core
核心Core: Version.h:版本控制信息,宏POCO_VERSION,值格式采用0xAABBCCDD,分别代表主版本.次版本.补丁版本.预发布版本: Poco.h:简单地包含了头文件Found ...
- POCO库——Foundation组件概述
Foundation组件作为POCO库的基础组件,主要包含了核心Core.缓存Cache.加解密Crypt.日期时间DateTime.动态类型Dynamic.事件events.文件系统Filesyst ...
- iOS开发系列—Objective-C之Foundation框架
概述 我们前面的章节中就一直新建Cocoa Class,那么Cocoa到底是什么,它和我们前面以及后面要讲的内容到底有什么关系呢?Objective-C开发中经常用到NSObject,那么这个对象到底 ...
- Introduction of OpenCascade Foundation Classes
Introduction of OpenCascade Foundation Classes Open CASCADE基础类简介 eryar@163.com 一.简介 1. 基础类概述 Foundat ...
- IOS开发之学习《AV Foundation 开发秘籍》
敲了这么久的代码,查阅了很多资料,都是网络电子版的,而且时间久了眼睛也累了,还不如看一下纸质的书籍,让眼睛休息休息. 本篇开始学习<AV Foundation 开发秘籍>,并记录对自己本人 ...
- 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 ...
- 测试环境搭建心得 vs2008+SQL2008 PHP+APACHE+mysql Team Foundation Server2013
大四即将结束,大学的最后一个假期,找到一份实习工作,担任测试工程师.在过年前的最后一周入职,干了一周的活儿.主要工作就是搭建测试环境. VMware 主要熟悉VMware软件,装系统基本都没什么问题. ...
- CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(1)设定背景图
技术的新发展,除计算机可以接入互联网之外,平板电脑.智能手机.智能电视等其他设备均可访问互联网.在多设备时代,构建多屏体验也不是听说的那么难. 但是这也增加了学习CSS的难度?不知道如何上手,只懂一点 ...
随机推荐
- CodeForces 219D 树形DP
D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...
- CSS DIV 独占一行,清除左右两边的浮动
clear:both //表示清除左右两边浮动的层,自己独占一行
- 微信APP支付Java后端回调处理
package com.gaoxiao.framework.controller.gaojia; import com.gaoxiao.framework.commonfiles.entity.Sta ...
- 2016HUAS暑假集训训练2 L - Points on Cycle
题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/L 这是一道很有意思的题,就是给定一个以原点为圆心的圆,然后给定 一个点 求最大三 ...
- HTML DOM insertBefore() 方法 使用的时候发现一个问题,记录下
在W3C中是这样定义的 第二个参数是可先的,但是在谷歌浏览器和火狐浏览器中测试是会有bug的,第二个参数是必填的,否则会报错 感兴趣的可以测试 以下是我测试的结果: 谷歌浏览器:Uncaught ...
- Mysql event学习
我们可能比较熟悉crond,但是mysql也有一个自己的叫event,oracle的叫job. 开启mysql的event有很多种方法,和临时开启.我们在配置文件里面添加参数,随着服务一起开启. 在[ ...
- CommonUtils.java
package com.vcredit.framework.utils; import java.lang.reflect.InvocationTargetException;import java. ...
- sprintf的缓冲区溢出问题
因为sprintf函数没有参数指定缓冲区的大小,这使得溢出的可能性很大,尤其是遇到 sprintf( buffer, "%s", a ) 如果不知道a的串长,就无法指定安全的缓冲区 ...
- You and Your Research(Chinese)
转自:http://lyxh-2003.iteye.com/blog/434014 这是大科学家Richard Hamming的著名讲演,于1986年在贝尔通讯研究中心给200多名Bellcore的科 ...
- ajax同步、异步执行简单理解与证明
此理解范例代码来自前几篇随笔! 首先我们来先了解下AJAX: Ajax:全称“Asynchronous Javascript and XML”(异步Javascript和XML),他是由Javascr ...