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的难度?不知道如何上手,只懂一点 ...
随机推荐
- maven pom文件结构详解
POM文件结构 Project Object Model是Maven2项目的基础所在,简单来说它就是一个XML文件,Maven2用它来描述一个工程的整个生命周期所需要执行的一系列功能和特性. 最小配置 ...
- jquery ui dialog去掉右上角的叉号
var dialog = $("#id").dialog({ resizable:false, height:, width:, zIndex:, modal:true, open ...
- MVC概念性的内容
MVC: 是一个缩写(model + view + control), Model:是一些类文件, 功能:负责增删改查, 负责跟数据库打交道 (把数据存入到数据库: 从数据库把数据读 ...
- Python开发问题和解决方案汇集
1.Sublime Text中用Tab批量替换空格Whitespace缩进:Ctrl+A全选代码,Ctrl+Shift+P打开下拉框,输入indent,找到Convert indentation to ...
- Linux启动过程
系统BIOS是当你点击开机键是第一个运行的程序.1. 首先主板需要接收到一个稳定的电源供给信号.如果没有得到稳定的电源供给系统自动关闭.2. 当接受到一个稳定的电源供给信号,处理器会启动,当处理器启动 ...
- JSP页面转向方式
1.RequestDispatcher.forward() 是在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个S ...
- BizTalk开发系列(六) BizTalk开发简述
现在很多大型企业信息化程度很高,运行中的系统可达到数十乃至上百个.而大部分系统由于建设的时间.开发团队和技术 往往不相同,系统之间的大部分都是独立运行的.随着信息化建设的深入各系统之间的交互需求越来越 ...
- Linux内核总结
1.文件系统就是数据的存储结构,不要以为你的硬盘存储东西理所当然,没有文件系统,你存的只是0010101101100 2.内存管理是计算机运行时内存的分配和使用. 3.进程管理就是说每次执行一个程序都 ...
- Sharepoint 2013 回收站知识整理
回收站机制可有利于防止内容的永久删除与误删除. 一.SharePoint 2013 回收站包括两种:第一回收站(End user Recycle Bin items)与 第二回收站(Deleted f ...
- MVC下载文件方式
MVC下载文件方式 http://www.cnblogs.com/liang--liang/archive/2012/10/20/2732745.html 方式一: public FileStream ...