homework-04
1.准备工作
本次结对编程我们对项目本身就行了分工,既然是测试来驱动开发,那么我们就把本次工作分成了测试与生成两个部分,小明同学负责生成测试数据,而我写测试程序检测测试结果是否正确,相对来说还是小明同学的那部分较为复杂。因为若想得到正确的结果,测试数据必然不能随机生成。然后我们就开始了我们的工作。
2.思路分析
先看下测试程序需要测试哪些功能?
a) Stage 1
a. Every phrase in the input file is covered once and only once.
b. No less than 2 of the phrases must be in these directions:
i. top-down, bottom-up, left-right, right-left, and all 4 diagonal directions.
c. The width and height of the matrix can be different
- d. there doesn’t exist a row or column of letters where none of the letters are covered (不存在一行或一列字母不被任何短语覆盖)。
b) Stage 2
a. The matrix must have the same width and height
Stage 3
The four corners of the output matrix must be occupied by a phrase.
看到了需求之后我们就能够确定我们需要记录哪些数据了?首先是每个phrase在输入文件中出现的次数,第二点是每个方向上出现的单词个数以及输入文件中每个字符的访问次数。
为了完成这项工程,首先想到的是深度优先搜索,但是由于需要对8个方向上进行深度优先搜索,函数的参数处理比较繁琐,并且考虑到输入矩阵不会太大,最终我们选择了暴力搜索的方式。
3.实际编码
#include<stdio.h>
#include<string.h> char s[][]; //传进来的字母矩阵
int visit[][];
int number; //需要放进去的单词数目
char verbal[][]; //需要放进去的单词
int lenth[]; //需要放进去的单词的长度
int d1,d2,d3,d4,d5,d6,d7,d8,d9;
int n; //矩阵大小
int check_verbal[]; //单词在s中出现的次数 int search_1(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
j++;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti][startj+i]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_2(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
i++;
j++;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti+i][startj+i]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_3(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
i++;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti+i][startj]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_4(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
i++;
j--;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti+i][startj-i]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_5(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
j--;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti][startj-i]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_6(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
i--;
j--;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti-i][startj-i]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_7(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
i--;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti-i][startj]=;
check_verbal[k]++;
return ;
}
else
return ;
} int search_8(int i,int j,int k)
{
int temp=;
int starti=i,startj=j;
while(i>&&j>&&i<=n&&j<=n&&temp<lenth[k]){
if(s[i][j]==verbal[k][temp]){
i--;
j++;
temp++;
}
else
return ;
}
if(temp==lenth[k]){
for(i=;i<lenth[k];i++)
visit[starti-i][startj+i]=;
check_verbal[k]++;
return ;
}
else
return ;
} void check()
{
int i,j;
int temp;
for(i=;i<number;i++){
if(check_verbal[i]!=){
printf("no");
return;
}
}
if(d1<=&&d2<=&&d3<=&&d4<=&&d5<=&&d6<=&&d7<=&&d8<=){
printf("no");
return;
}
for(i=;i<=n;i++){
temp=;
for(j=;j<=n;j++)
temp+=visit[i][j];
if(temp==){
printf("no");
return;
}
}
for(j=;j<=n;j++){
temp=;
for(i=;i<=n;i++)
temp+=visit[i][j];
if(temp==){
printf("no");
return;
}
}
temp=visit[][]+visit[][n]+visit[n][]+visit[n][n];
if(temp==){
printf("no");
return;
}
printf("yes");
} int main()
{ int i,j,k;
freopen("read.in","r",stdin);
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%s",&s[i]);
for(i=;i<=n;i++){
for(j=;i<=n;j++){
for(k=;k<number;k++){
if(s[i][j]=verbal[k][]){
if(search_1(i,j,k)==){
d1++;
if(search_2(i,j,k)==)
d2++;
if(search_3(i,j,k)==)
d3++;
if(search_4(i,j,k)==)
d4++;
if(search_5(i,j,k)==)
d5++;
if(search_6(i,j,k)==)
d6++;
if(search_7(i,j,k)==)
d7++;
if(search_8(i,j,k)==)
d8++;
}
}
}
}
check();
fclose(stdin);
return ;
}
看起来是不是很长,但是实际上功能很简单,只不过是需要进行8个方向上的搜索,子函数较多一些。当然这个代码是最初版本,当我从梦中惊醒的时候发现数组开小了,每个方向至少有两个phrase,那么至少就要有16个phrase,而我预先假定的是不超过10个phrase。所以代码还需要进行下一步的修改。
未完待续中。。。
4.测试结果




5、时间统计
|
Personal Software Process Stages |
时间百分比(%) |
实际花费的时间 (分钟) |
原来估计的时间 (分钟) |
|
计划 |
10% | 18 | 12 |
|
· 估计这个任务需要多少时间,把工作细化并大致排序 |
10% | 18 | 12 |
|
开发 |
85% | 153 | 102 |
|
· 需求分析 (包括学习新技术) |
15% | 27 | 18 |
|
· 设计复审 (和同事审核设计文档) |
10% | 18 | 12 |
|
· 代码规范 (制定合适的规范) |
5% | 9 | 6 |
|
· 具体设计 |
10% | 18 | 12 |
|
· 具体编码 |
35% | 63 | 42 |
|
· 代码复审 |
5% | 9 | 6 |
|
· 测试(自我测试,修改代码,提交修改) |
5% | 9 | 6 |
|
总结报告 |
5% | 9 | 6 |
|
总计 |
100% | 总用时 180 |
homework-04的更多相关文章
- 现代程序设计homework——04
题目: 详见:http://www.cnblogs.com/xinz/p/3341551.html 题目本身确实很难,“很难想到一个比较优雅的算法”,这是一个老师请来专门讲解这道题的大牛的原话.确实, ...
- 小兔JS教程(四)-- 彻底攻略JS数组
在开始本章之前,先给出上一节的答案,参考答案地址: http://www.xiaotublog.com/demo.html?path=homework/03/index2 1.JS数组的三大特性 在J ...
- 小兔JS教程(五) 简单易懂的JSON入门
上一节的参考答案: http://xiaotublog.com/demo.html?path=homework/04/index2 本节重点来介绍一下JSON,JSON(JavaScript Obje ...
- hdu--1798--Doing Homework again(贪心)
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Final阶段第1周/共1周 Scrum立会报告+燃尽图 04
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2483] 版本控制:https://git.coding.net/liuyy08 ...
- 20181009-5 选题 Scrum立会报告+燃尽图 04
Scrum立会报告+燃尽图(04)选题 此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2194] 一.小组介绍 组长:刘 ...
- Beta阶段第2周/共2周 Scrum立会报告+燃尽图 04
此作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2412 版本控制地址 [https://git.coding.net/ ...
- 20181113-7 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 04
作业要求:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2386] 版本控制:[https://git.coding.net/lglr2 ...
- 20181016-4 Alpha阶段第1周/共2周 Scrum立会报告+燃尽图 04
此作业要求https://edu.cnblogs.com/campus/nenu/2018fall/homework/2248 Scrum master:徐常实 一.小组介绍 组长:王一可 组员:范靖 ...
- Python学习--04条件控制与循环结构
Python学习--04条件控制与循环结构 条件控制 在Python程序中,用if语句实现条件控制. 语法格式: if <条件判断1>: <执行1> elif <条件判断 ...
随机推荐
- 整理了一份招PHP高级工程师的面试题
1. 基本知识点 HTTP协议中几个状态码的含义:1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码 ...
- C++ 11 vlearning
1.新增算术类型 longlong,最小不比long小,一般为64位. 2.列表初始化 int units_sold = {0};或者 int units_sold{0};非11标准 ...
- Image.FrameDimensionsList 属性-----具体使用案例2
图片的拆分 1.保存png图片 using System; using System.Collections.Generic;using System.ComponentModel;using Sys ...
- php扩展函数调用扩展中的标准函数
这几天在写php的扩展函数,在网上学习步骤什么的都有,一般问题也都能查到,所以就不再此啰嗦,写这篇博客的原因是因为遇到的一个问题,百度谷歌都没找到,对于初学者,这个或许有用,对于过来人,我想他们肯定也 ...
- MyBatis学习总结4--解决字段名与实体类属性名不相同的冲突
在平时的开发中,我们表中的字段名和表对应实体类的属性名称不一定是完全相同的,如果直接在xml映射文件中使用sql进行映射,会造成返回值为空的情况,下面阐述解决方案: 测试所用表和数据 create t ...
- mysql if 和 case when 用法 多个when情况用一个语句 存储过程
在实际开发中,经常会用到 if 和 case when的用法,记录一下,以后可以用得到. DELIMITER $$ USE `数据库`$$ DROPPROCEDUREIFEXISTS `GetNoti ...
- linux + ffmpeg + eclipse 调试
使用linux + ffmpeg + eclipse调试步骤OS : ubuntu 12.04Eclipse : 3.7.2 为Eclipse安装cdt插件,使其支持c/c++ 导入ffmpeg项目 ...
- 海康、大华IpCamera RTSP地址和格式
海康:rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream说明:username: 用户名.例如 ...
- <三>面向对象分析之UML核心元素之参与者
一:版型 --->在UML里有一个概念叫版型.有些书里也称类型,构造型. --->这个概念是对一个UML元素基础定义的扩展.在同一个元素基础定义的基础上赋予特别 ...
- PL/Sql 中创建、调试、调用存储过程
存储过程的详细建立方法 1.先建存储过程 左边的浏览窗口选择 procedures ,会列出所有的存储过程,右击文件夹procedures单击菜单"new",弹出 template ...