杭电2012年笔试

1.十进制 -> 十六进制

写一程序 将十进制转换为 十六进制,每行输入一个十进制数,当输入数为0的时候,程序结束。

输入样例:

5
242
0

输出样例:

5
F2

 思路:

十进制->Q进制:除基取余法

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
// 当输出大于9的数字时,输出对应的字符数组
char hexa[6] = { 'A','B', 'C', 'D', 'E', 'F' };
int main() {
	int n, Q = 16;
	scanf("%d", &n);
	do {
		int z[40], pNum = 0; // 存放余数数组和下标
		while (n != 0) {
			z[pNum++] = n % Q; // 取余数
			n = n / Q; 
		}
        // 输出当前Q进制数
		for (int i = pNum - 1; i >= 0; i--) {
			if (z[i] > 9)
				printf("%c", hexa[z[i] - 10]);
			else
				printf("%d", z[i]);
			if (i == 0)
				printf("\n");
		}
        // 再录入十进制数n
		scanf("%d", &n);
	} while (n != 0);
	return 0;
	
}

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 numbers (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 multiple problems instances. The input for each problem instance will be on two lines. The first line is an integer 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 letter, 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 move 1.

 

weixin028基于微信小程序小说阅读器设计+ssm后端毕业源码案例设计 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值