程序是生成一个10X10的字符数组,初始化时全为 ‘.’  的随机步法。程序必须随机的从一个元素 ‘走到’ 另一个元素,每次只向上、向下、向左或向右移动一个元素位置。已访问过的元素按访问顺序用字母A到Z进行标记。

考察srand和rand的使用

代码不是太好,只能简单实现

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h> int main()
{
char str[][];
char point = 'A';
int i,j,k,t;
int randd;
for(i=; i<; i++)
{
for(j=; j<; j++)
{
str[i][j] = '.';
}
}
srand((unsigned)time(NULL));
i = ; j = ;
str[i][j] = 'A';
while(point != 'Z')
{
randd = rand() % ;
if(randd == && i- >= && str[i-][j] == '.')//判断条件
{
str[i-][j] = ++point;
i -= ;
}
else if(randd == && j+ < && str[i][j+] == '.')
{
str[i][j+] = ++point;
j += ;
}
else if(randd == && i+ < && str[i+][j] == '.')
{
str[i+][j] = ++point;
i +=;
}
else if(randd == && j- >= && str[i][j-] == '.')
{
str[i][j-] = ++point;
j -= ;
}
else if(str[i-][j] != '.' && str[i][j+] != '.' && str[i+][j] != '.' && str[i][j-] != '.')
{
break;//通过边界测定,判断跳出情况
}
//else randd = rand() % 4;;
} for(i=; i<; i++)
{
for(j=; j<; j++)
{
printf("%c",str[i][j]);
}
printf("\n");
}
return ;
}

随机步法A-Z的更多相关文章

  1. 随机生成A~Z的字母CharDemo

  2. Python生成随机验证码,大乐透号码

    实例笔记之生成随机号码 扩展知识 - yield(生成器) 随机生成验证码 示例代码: import random # 导入标准模块中的random if __name__ == '__main__' ...

  3. python序列,字典备忘

    初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...

  4. LFI漏洞利用总结

    主要涉及到的函数 include(),require().include_once(),require_once() magic_quotes_gpc().allow_url_fopen().allo ...

  5. 重拾java系列一java基础(1)

    前言,不知不觉,从接触java到工作至今已有两年的时间,突然感觉自己的基础知识还很薄弱,有些知识虽然知道,但是停留在表面上,没有深挖,或者实践过,感觉掌握的很肤浅,而且时间一长,就觉得忘记了,我觉得这 ...

  6. LFI漏洞利用总结(转载)

    主要涉及到的函数include(),require().include_once(),require_once()magic_quotes_gpc().allow_url_fopen().allow_ ...

  7. MySQL扩展

    一.使用MySQL特有的函数!        1>到年底还有几天            select datediff('2014-12-31','2014-6-21');//此函数用于计算日期 ...

  8. 7.python常用模块

    1.time 常用表示时间方式: 时间戳,格式化的时间字符串,元组(struct_time) UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时 ...

  9. GAN 转

    生成式对抗网络(GAN)是近年来大热的深度学习模型.最近正好有空看了这方面的一些论文,跑了一个GAN的代码,于是写了这篇文章来介绍一下GAN. 本文主要分为三个部分: 介绍原始的GAN的原理 同样非常 ...

随机推荐

  1. Ul li 横排 菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. android 项目学习随笔十九(MD5)

    import java.security.MessageDigest; public class MD5Encoder { public static String encode(String str ...

  3. TreeNode动态邦定事件

    1. 显示不能用TextField,应该用StaticText 2. public void SetNodesAction(Tree t, String methodbind){ ArrayList ...

  4. rotate array 旋转数组

    class Solution {public: void rotate(vector<int>& nums, int k) { int n=nums.size(); int i=0 ...

  5. pgadmin(IDE)工具连接postgres数据库

    1. 下载软件        软件地址:http://www.pgadmin.org/download/pgagent.php   2.安装软件    安装过程:略    打开软件64位会出现  “无 ...

  6. SpringMVC 接收复杂对象

    要发送的数据为:String topicId,String topicName,String summarize,List<ModuleParam> parentList 前端页面ajax ...

  7. 每日一九度之 题目1023:EXCEL排序

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18804 解决:4240 题目描述:     Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能.     对每个测试用例 ...

  8. Python 日期和时间

    Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时间间隔是以秒为单位的浮点小数. ...

  9. Train Problem I 分类: HDU 2015-06-26 11:27 10人阅读 评论(0) 收藏

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. Elevator 分类: HDU 2015-06-19 21:52 13人阅读 评论(0) 收藏

    Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...