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的难度?不知道如何上手,只懂一点 ...
随机推荐
- SPARK 中 DriverMemory和ExecutorMemory
spark中,不论spark-shell还是spark-submit,都可以设置memory大小,但是有的同学会发现有两个memory可以设置.分别是driver memory 和executor m ...
- hdu Is It A Tree?
判定给定的边序列是否过程一棵树.我用到的判定方法是:第一步:判定 边数是否等于顶点数-1 第二:判定是否只有一个根节点 .当然还要考虑是否为空树的情况. 但是代码交上去,好几遍都是Runtime ...
- 织梦5.7 TAG、标题、栏目以及keywords长度字符数限制修改
织梦5.7 TAG.标题.栏目以及keywords长度字符数限制修改[图文] 标签: 织梦关键词长度修改 织梦tag长度修改 织梦标题长度修改 织梦栏目长度限制修改 织梦修改 分类: 技术操作 ...
- Socket客户端/服务端简单实例
1.client端 package demo.socket; import java.io.BufferedReader;import java.io.IOException;import java. ...
- 已知一个日期和天数, 求多少天后的日期(是那个超时代码的AC版)
#include <stdio.h> #include <string.h> ; int judge_year(int x) { == || x % == && ...
- find exec 运用
实例1:ls -l命令放在find命令的-exec选项中 : find . -type f -exec ls -l {} \; 实例2:在目录中查找更改时间在n日以前的文件并删除它们: find . ...
- segement fault常见错误
1.指针赋值前就用它引用内存,或释放后继续访问它的内容. 2.释放同一块内存两次.
- 杭电ACM 1013 Digital Root
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){char s[100000];int ...
- mysql替换制定的内容的 类似正则表达式的功能
content= 'asnfojassozxpdsgdspdps神龙架谁骄傲的骄傲搜ID飞机扫' SELECT content FROM test WHERE id =1 吧zx替换成ZZZZ UPD ...
- ExtJS笔记 Ext.data.Model
A Model represents some object that your application manages. For example, one might define a Model ...