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

  1. 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的更多相关文章

  1. 现代程序设计homework——04

    题目: 详见:http://www.cnblogs.com/xinz/p/3341551.html 题目本身确实很难,“很难想到一个比较优雅的算法”,这是一个老师请来专门讲解这道题的大牛的原话.确实, ...

  2. 小兔JS教程(四)-- 彻底攻略JS数组

    在开始本章之前,先给出上一节的答案,参考答案地址: http://www.xiaotublog.com/demo.html?path=homework/03/index2 1.JS数组的三大特性 在J ...

  3. 小兔JS教程(五) 简单易懂的JSON入门

    上一节的参考答案: http://xiaotublog.com/demo.html?path=homework/04/index2 本节重点来介绍一下JSON,JSON(JavaScript Obje ...

  4. hdu--1798--Doing Homework again(贪心)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. Final阶段第1周/共1周 Scrum立会报告+燃尽图 04

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2483] 版本控制:https://git.coding.net/liuyy08 ...

  6. 20181009-5 选题 Scrum立会报告+燃尽图 04

    Scrum立会报告+燃尽图(04)选题 此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2194] 一.小组介绍 组长:刘 ...

  7. Beta阶段第2周/共2周 Scrum立会报告+燃尽图 04

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2412 版本控制地址    [https://git.coding.net/ ...

  8. 20181113-7 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 04

    作业要求:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2386] 版本控制:[https://git.coding.net/lglr2 ...

  9. 20181016-4 Alpha阶段第1周/共2周 Scrum立会报告+燃尽图 04

    此作业要求https://edu.cnblogs.com/campus/nenu/2018fall/homework/2248 Scrum master:徐常实 一.小组介绍 组长:王一可 组员:范靖 ...

  10. Python学习--04条件控制与循环结构

    Python学习--04条件控制与循环结构 条件控制 在Python程序中,用if语句实现条件控制. 语法格式: if <条件判断1>: <执行1> elif <条件判断 ...

随机推荐

  1. TCP和UDP协议的应用/参数查看

    TCP发送的包有序号,对方收到包后要给一个反馈,如果超过一定时间还没收到反馈就自动执行超时重发,因此TCP最大的优点是可靠.一般网页(http).邮件(SMTP).远程连接(Telnet).文件(FT ...

  2. android自动更新软件版本

    根据网上的然后小改 import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import j ...

  3. jquery live hover绑定方法

    $(".select_item span").live({ mouseenter: function() { $(this).addClass("hover") ...

  4. js对联广告代码,兼容性高

    var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXO ...

  5. cocos2d-x 滚动文字(二)

    http://blog.csdn.net/kuovane/article/details/8131789 首先送上demo,下载地址为:demo下载地址 一,怎么在文字前面空两隔?只需在xml里的文字 ...

  6. Java [Leetcode 268]Missing Number

    题目描述: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is ...

  7. jvm内部现成运行

    hi,all 最近抽时间把JVM运行过程中产生的一些线程进行了整理,主要是围绕着我们系统jstack生成的文件为参照依据.  前段时间因为系统代码问题,造成性能瓶颈,于是就dump了一份stack出来 ...

  8. 【再见RMQ】NYOJ-119-士兵杀敌(三),区间内大小差值

    [题目链接:NYOJ-119] 思路:转自 点我 ,讲的挺好. #include <cstdio> #include <math.h> #define max(a,b) ((a ...

  9. 嵌入式 hi3518c平台网卡模式MII与RMII模式在Uboot和kernel中切换小结

    由于公司项目的需要,我们需要在原有的MII的基础上,修改为RMII模式,针对hi3518c平台,我的网卡是LAN8701需要修改的地方有如下几个: 首先我的uboot中env是: bootargs=m ...

  10. ioctl用法详解 (网络)

    本函数影响由fd参数引用的一个打开的文件. #include#include int ioctl( int fd, int request, .../* void *arg */ );返回0:成功   ...