1、Github地址:https://github.com/yefenqin/sudo-
2、解题思路:项目包括 输入与输出(文件读写、命令行),生成不重复终局,解数独三个部分。
(1)输入与输出
文件的读写和使用命令行以前没有接触,通过询问同学和阅读别的同学代码解决这个问题。
(2)生成不重复终局
先确定第一行的九个数,因为第一位是固定的不能改动,改动其他八位数字,第一行全排列有8!=40320种,然后对4-6,7-9行进行交换,再乘3!×3!,结果略大于1e6。
(3)解数独
使用递归,每一列已有的数字标记1,每一行已有的数字标记1,每一块已有的数字标记1。
将未被标记的数字依次填入然后检验即可。
3、代码设计
(1)函数功能
int main(int ,char *) :获取命令行参数,进入不同处理函数
void create(int n):参数为-c时:生成终局存入数组并输出
void solve(char path[]):参数为-s时:标记每行每列每块已有的数字,并进入递归函数fun()
void fun(int x,int y):通过递归解出数独,并且输出
(2)关键函数
生成终局:

解数独:

(3)单元测试
命令行参数判定:-c, -s,
运行情况判定:-c 1, -c 1000, -c 1000000, -s 文件路径(其中包含1、1000个用例)
4、运行分析
(1)生成数独终局
(2)解20-40个空格的数独
5.PSP
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
Planning |
计划 |
40 |
60 |
·Estimate |
·估计这个任务需要多少时间 |
20 |
20 |
Development |
开发 |
1000 |
1000 |
·Analysis |
·需求分析(包括学习新技术) |
200 |
200 |
·Design Spec |
·生成设计文档 |
120 |
90 |
·Design Review |
·设计复审 |
30 |
30 |
·Coding Standard |
·代码规范 |
30 |
30 |
·Design |
·具体设计 |
200 |
200 |
·Coding |
·具体编码 |
480 |
480 |
·Code Review |
·代码复审 |
30 |
30 |
·Test |
·测试 |
30 |
60 |
Reporting |
报告 |
180 |
180 |
·Test Report |
·测试报告 |
40 |
40 |
·Size Measurement |
·计算工作量 |
10 |
10 |
·Postmortem&Process Improvement Plan |
·事后总结并提出过程改进计划 |
90 |
90 |
|
合计 |
2500 |
2520
|