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的难度?不知道如何上手,只懂一点 ...
随机推荐
- js实现时钟
<!DOCTYPE html> <html> <head> <title>Js版带表盘的时钟</title> <meta charse ...
- php发送邮件处理功能页面去除重复的邮箱地址
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JavaScript 入门教程二 在HTML中使用 JavaScript
一.使用 <script> 元素的方式有两种:直接在页面中嵌入 JavaScript 代码和引用外部 JavaScript 文件. 二.使用内嵌方式,一般写法为: <script t ...
- 没有对“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files”的写访问权限 的解决方案
问题情况: 在64位机器上运行Web服务,然后在配置好之后测试访问的时候出现如下提示:
- Shell displays color output
格式: echo "/033[字背景颜色;字体颜色m字符串/033[控制码" 如果单纯显示字体颜色可以固定控制码位0m. 格式: echo "/033[字背景颜色;字体颜 ...
- entity.Student@150f3932, entity.Student@1a740c6b 没有实体中的数据
public class AppServerAction extends BaseAction { /** * */ /** * 初始化 “我的产品”列表 JSP页面 ...
- Diablo2 1.13版&PlugY10.00 男巫存档
下载地址: http://files.cnblogs.com/files/xiandedanteng/20160805D2113NanwuL83Backup.rar 解压后文件放到Diablo2游戏的 ...
- TCP三次握手四次挥手详解
转载 http://www.cnblogs.com/zmlctt/p/3690998.html 相对于SOCKET开发者,TCP创建过程和链接折除过程是由TCP/IP协议栈自动创建的.因此开发者并不需 ...
- mac上卸载oracle jdk 1.8.0_31
mac上卸载oracle jdk 1.8.0_31版本,因为版本太高了.得安装旧版本才行.卸载的顺序是:进入finder,然后点应用程序,按command+向上箭头键,分别进入根目录的系统与资源库找到 ...
- JS错误捕获
try/catch/finally错误捕获 try { //一旦try中出现错误,直接跳到执行catch的内容,执行完catch的内容,代码继续执行 throw new Error('错误'); // ...