1.写一程序将十进制数转变为十六进制数输出。每行输入一个十进制数,当输入数位0时,输出结束。

#include<stdio.h>
#include<string.h>
int n,i;
char sixteen[10000];
void main()
{while(scanf("%d",&n)!=EOF&&n){int k=0;memset(sixteen,'\0',sizeof(sixteen));while(n){if(n%16<10)sixteen[k++]=n%16+'0';elsesixteen[k++]=n%16+55;n/=16;}for(i=k-1;i>=0;i--)printf("%c",sixteen[i]);printf("\n");}
}

2.Worm is an old computer game.There are many versions,but all involve maneuvering a "worm"around the screen,trying to avoid running the worm into itself or an obstacle.

We'll simulate a very simplified version here.The game will be played on a 50×50 board,numbered so that the square at the upper left is numbered(1,1).The worm is initially a string of 20 connected squares.Connected squares are adjacent horizontally or vertically.The worm starts stretched out horizontally in positions(25,11)through(25,30),with the head of the worm at (25,30).The worm can move either East(E),West(W),North(N) or South(S),but will never move back on itself.So,in the initial position ,a W move is not possible.Thus the only two squares occupied by the worm that change in any move are its head and tail.Note that the head of the worm can move to the square just vacated by the worm's tail.

You will be given a series of moves and will simulate the moves until either the worm runs into itself,the worm runs off the board,or the worm successfully negotiates its list of moves.In the first two cases you should ignore the remaining moves in the list.

Input

There will be mutiple problems instances.The input for each problem instance will be on two lines.The first line is an integer n(n<100)indicating the number of moves to follow.(A value of n=0 indicates end of input.)The next line contains n characters(either E,W,N or S)with no spaces separating the letters,indicating the sequence of moves.

Output

Generate one line of output for each problem instance.The output line should be one of the follow three:

The worm ran into itself on move m.

The worm ran off the board on move m.

The worm successfully made all m moves.

where m is for you to determine and the first move is move1.

Sample Input

18

NWWWWWWWWWWSESSSWS

20

SSSWWNENNNNNWWWWSSSS

30

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

13

SWWWWWWWWWNEE

0

Sample Output

The worm successfully made all 18 moves.

The worm ran into itself on move 9.

The worm ran off the board on move 21.

The worm successfully made all 13 moves.

#include<stdio.h>
#include<string.h>
int matrix[52][52];
char route[10000];
int n,f,i;
void find_tail(int *t1,int *t2,int step)
{if(step<20)*t2=*t2+1;else{if(route[step-20]=='E')*t2=*t2+1;if(route[step-20]=='N')*t1=*t1-1;if(route[step-20]=='W')*t2=*t2-1;if(route[step-20]=='S')*t1=*t1+1;}
}
void main()
{while(scanf("%d",&n)!=EOF&&n){getchar();int head1=25,head2=30,tail1=25,tail2=11;memset(matrix,0,sizeof(matrix));for(i=11;i<=30;i++)matrix[25][i]=1;for(i=0;i<n;i++)scanf("%c",&route[i]);f=0;for(i=0;i<n;i++){if(route[i]=='E'){if(matrix[head1][head2+1]==1){if(head2+1==tail2&&head1==tail1)break;printf("The worm ran into itself on move %d.\n",i+1);f=1;break;}if(head2==50){printf("The worm ran off the board on move %d.\n",i+1);f=2;break;}matrix[head1][++head2]=1;matrix[tail1][tail2]=0;find_tail(&tail1,&tail2,i+1);}if(route[i]=='W'){if(matrix[head1][head2-1]==1){if(head2-1==tail2&&tail1==head1)break;printf("The worm ran into itself on move %d.\n",i+1);f=1;break;}if(head2==1){printf("The worm ran off the board on move %d.\n",i+1);f=2;break;}matrix[head1][--head2]=1;matrix[tail1][tail2]=0;find_tail(&tail1,&tail2,i+1);}if(route[i]=='S'){if(matrix[head1+1][head2]==1){if(head1+1==tail1&&head2==tail2)break;printf("The worm ran into itself on move %d.\n",i+1);f=1;break;}if(head1==50){printf("The worm ran off the board on move %d.\n",i+1);f=2;break;}matrix[++head1][head2]=1;matrix[tail1][tail2]=0;find_tail(&tail1,&tail2,i+1);}if(route[i]=='N'){if(matrix[head1-1][head2]==1){if(head1-1==tail1&&head2==tail2)break;printf("The worm ran into itself on move %d.\n",i+1);f=1;break;}if(head1==1){printf("The worm ran off the board on move %d.\n",i+1);f=2;break;}matrix[--head1][head2]=1;matrix[tail1][tail2]=0;find_tail(&tail1,&tail2,i+1);}if(f!=0)break;//        printf("(%d,%d)(%d,%d)\n",head1,head2,tail1,tail2);}if(!f)printf("The worm successfully made all %d moves.\n",n);}
}

这其实大概就是讲了一个贪吃蛇的游戏,让你判断这条长20格的贪吃蛇会不会撞墙,会不会撞到自己,还是顺利行动了。

就用一个矩阵来表示,1表示贪吃蛇身子所在的位置,0表示贪吃蛇不在的位置,如果头撞到了1所在的位置就是撞到了自己,如果头超出了50*50的格子,就是撞墙了。就是读入一格方向,头往那个所在方向的格子记1,尾所在的位置变0.

我中间出的错就是 没注意如果贪吃蛇的头下一步要碰到他的尾的话,其实是没事的,因为头跟尾一起动的,就是第四组数据。

总结这题真的不难,但是很多小细节真的很容易出错。。所以做了好久好久。

3.10 杭电复试题2012相关推荐

  1. 3.12 杭电复试题2014

    1.如果您曾经尝试在 Macintosh 上阅读 html 文档,您就知道如果没有安装网 景,那是多么困难. 现在,谁能忘记安装 HTML 浏览器呢?这很简单,因为大多数时候你在 MAC 电脑上不需要 ...

  2. 3.7 杭电复试题2011

    1.输入三个正整数 A.B.C,判断这三个数能不能构成一个三角形. #include<stdio.h> int i,a,b,c; void swap(int *m,int *n) {int ...

  3. 3.6 杭电复试题2010

    1.猜数字游戏   题目:随即产生一个 3 位的正整数,让你进行猜数字,如果猜小了,输出: "猜小了,请继续". 如果猜大了,输出:"猜大了,请继续".如果猜对 ...

  4. 3.6 杭电复试题2009

    1.输入两个整数,求出最大公约数. #include<stdio.h> int i,res,a,b; void swap(int *m,int *n) {int temp;temp=*m; ...

  5. 3.5 杭电复试题 2006

    1.输入一个十进制的数,把它变成八进制,类似的把十进制变成 16 进制, 把十六进制转变为十进制等. #include<stdio.h> #include<math.h> in ...

  6. 3.5 杭电复试题2007

    1."回文串"是一个正读和反读都一样的字符串,比如"level"或者"noon" 等等就是回文串.请写一个程序判断读入的字符串是否是&quo ...

  7. 3.12 杭电复试题2013

    1.简要描述:输入一个数,代表要检测的例子的个数,每个例子中:输入两 个时间(格式 HH:MM:SS),前面时间减去后面时间输出在时钟上显示的时间,格 式一样,如果是以为数字的前面补零. #inclu ...

  8. 【ACM】杭电OJ 2012。

    题目链接:杭电OJ 2012 思路很简单,但是有一种高效算法显示编译错误,不知道为什么 运行环境:VS2017 AC代码: #include <stdio.h> #include < ...

  9. Java:关于main方法的10道面试题

    转载自 Java:关于main方法的10道面试题 1.main方法是做什么用的? 2.不用main方法如何运行一个类? 3.main方法如何传递参数?传递参数的类型是什么?能不能改变该参数类型? 4. ...

最新文章

  1. [JS] [编程题] 配置文件恢复
  2. 【转】Plotting texts as graphs with R and igraph
  3. SpringCloud教程- 断路器(Hystrix)(SpringCloud版本Finchley)
  4. 目前最常用的计算机机箱类型为_常用的计算机设备
  5. BABOK - 需求管理和沟通(Requirements Management and Communication)概要
  6. strcpy ,strncpy ,strlcpy地用法
  7. flash 绘图API:绘制秀曲线图形
  8. DRL实战 : 强化学习在广告点击业务中的应用
  9. 测试网络速度的软件 哪款好,网络测速工具有哪些?2018网络测速工具推荐
  10. Stardict 81部中文词典下载
  11. 制图折断线_cad折断线怎么画,你值得一看的技巧
  12. 安装WIN10系统时“谁将会使用这台电脑”输入卡死状态的问题
  13. 怎么将WPS转换成WORD?看完你就学会了
  14. godaddy构建ddns服务
  15. iPhone共享WIFI密码到Macbook - 无需在Mac上使用WIFI万能钥匙
  16. (二)苏世民:我的经验和教训:追梦(12)
  17. DM8在银河麒麟服务器上配置Oracle19c的DBLINK服务
  18. 计算机课程打字教学,打字教程第1课 认识键盘
  19. 图书推荐:《Web前端黑客技术揭秘》
  20. 【初篇】DHT11连接STM32、One wire单总线原理、GPIO代码详解

热门文章

  1. 这个母亲节的礼物,我为你们准备好了!(内含福利)
  2. [跬步]说说如何自主学习
  3. Keras.layers.core.dense()方法详解
  4. 缓存更新脏读问题总结
  5. 一度智信:拼多多平台开网店怎么收费?
  6. 报告:Facebook的Calibra数字钱包将无法在其所有市场上销售
  7. 软考专题模块:2014年下半年软件设计师考试上午试题
  8. 线性代数(3):矩阵
  9. 60V输入电压LDO,MST56XXB
  10. 终于,月入 20000 !!