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 <条件判断 ...
随机推荐
- QTP鼠标点击和浏览器事件的动态切换
今天在群里有人问到一个问题,我觉得应该会有很多人会碰到,今天根据自己的思路把这个解决方案整理出来,供自己和大家参考 需求描述: 当输入一个身份证号码的时候,这个号码所对应的数据会被加载到所属的省和市的 ...
- Linux进程调度和切换过程分析
内容: (1):从schedule()开始,几种不同类型的进程之间的调度选择;在相同类型的进程之间的调度选择算法 (2):从CPU的IP值的变化上,说明在switch_to宏执行后,执行分析 (3): ...
- android4.4内核移植
01 init/目录下Kconfig修改: 956行添加: config PANIC_TIMEOUT int "Default panic timeout" help Set de ...
- Ogre内存池的使用和说明
大家可能会遇到一些Ogre中的内存分配的方面问题,我对这个总结了一下内存分配的方面资料. Ogre在1.7版本后,统一了内存分配策略,提供了内存是否泄漏的跟踪和内存池等比较方便开发的一些策略,目前提供 ...
- UVa 1635 (唯一分解定理) Irrelevant Elements
经过紫书的分析,已经将问题转化为求组合数C(n-1, 0)~C(n-1, n-1)中能够被m整除的个数,并输出编号(这n个数的编号从1开始) 首先将m分解质因数,然后记录下每个质因子对应的指数. 由组 ...
- HDU 1686 (KMP模式串出现的次数) Oulipo
题意: 求模式串W在母串T中出现的次数,各个匹配串中允许有重叠的部分. 分析: 一开始想不清楚当一次匹配完成时该怎么办,我还SB地让i回溯到某个位置上去. 后来仔细想想,完全不用,直接让模式串向前滑动 ...
- BZOJ_1028_[JSOI2007]_麻将_(模拟+贪心)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1028 同一种花色的牌,序数为\(1,2,...,n\).定义"和了"为手上 ...
- Java [Leetcode 235]Lowest Common Ancestor of a Binary Search Tree
题目描述: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in ...
- MySQL基础之第1章 数据库概述
1.1.数据存储方式 1.人工管理阶段2.文件系统阶段3.数据库系统阶段 1.2.数据库泛型 数据库泛型就是数据库应该遵循的规则.数据库泛型也称为范式.目前关系数据库最常用的四种范式分别是:第一范式( ...
- Creating SharePoint 2010 Event Receivers in Visual Studio 2010
转:http://msdn.microsoft.com/en-us/library/gg252010(v=office.14).aspx Summary: Learn how to create a ...