zoukankan      html  css  js  c++  java
  • 2020软件工程作业03

    2020软件工程作业03

    作业课程 https://edu.cnblogs.com/campus/zswxy/software-engineering-2017-1
    作业要求 https://edu.cnblogs.com/campus/zswxy/software-engineering-2017-1/homework/10494
    作业目标 实现Sudoku
    作业正文 见下文
    参考文献 百度

    1.Github项目地址

    https://github.com/james-wade23/20177685

    2.PSP表格

    PSP2.1 Personal Software Process Stages 预估耗时(小时) 实际耗时(小时)
    Planning 计划 4 5
    Estimate 估计这个任务需要多少时间 20 48
    Development 开发 6 8.5
    Analysis 需求分析 (包括学习新技术) 4 5
    Design Spec 生成设计文档 2.5 3.5
    Design Review 设计复审 3 3
    Coding Standard 代码规范 (为目前的开发制定合适的规范) 1.5 2
    Design 具体设计 1.5 1.5
    Coding 具体编码 6 8
    Code Review 代码复审 3 4
    Test 测试(自我测试,修改代码,提交修改 2 2.5
    Reporting 报告 1 1.5
    Test Repor 测试报告 1 1.5
    Size Measurement 计算工作量 0.5 1
    Postmortem & Process Improvement Plan 事后总结, 并提出过程改进计划 2 3
    合计 58 94

    3.需求

    实现一个命令行程序,不妨称之为Sudoku。

    4.解题思路

    第一眼看到很懵,无从下手,只能通过百度找寻资料才可以勉强了解一下这个题目。要知道使用回溯,对相关命令进行传参。可以使用排除法进行每行每列的排列。题目要求是做成九宫格形式,对应的就是九阶独数矩阵。不能使用空格。

    5.代码分析

    package Test;

    import java.util.Scanner;

    public class Gongge {
    public static int[][] group = new int[9][9];
    public static int[][] value = new int[9][9];
    public static int[][] row = new int[9][9];
    public static int[][] ring = new int[9][9];
    public static int[][] get_group = new int[9][9];

    public void init() {
        String[] S = new String[9];
        for(int i = 0;i < 3;i++) {
            S[i] = "000111222";
            S[3 + i] = "333444555";
            S[6 + i] = "666777888";
        }
        for(int i = 0;i < 9;i++) {
            for(int j = 0;j < S[i].length();j++) {
                group[i][j] = S[i].charAt(j) - '0';
            }
        }
        for(int i = 0;i < 9;i++) {
            for(int j = 0;j < 9;j++) {
                row[i][j] = -1;
                ring[i][j] = -1;
                get_group[i][j] = -1;
            }
        }
    }
    
    public void dfs(int step) {
        if(step == 81) {
            for(int i = 0;i < 9;i++) {
                for(int j = 0;j < 9;j++) {
                    System.out.print(value[i][j]);
                }
                System.out.println();
            }
            return;
        } else {
            int x = step / 9;
            int y = step % 9;
            if(value[x][y] > 0) {
                dfs(step + 1);
            } else {
                for(int i = 1;i <= 9;i++) {
                    if(row[x][i - 1] == -1 && ring[y][i - 1] == -1 &&
                            get_group[group[x][y]][i - 1] == -1 && value[x][y] == 0) {//这里可以判断行列宫中有无重复值
                        value[x][y] = i;
                        row[x][i - 1] = 1;
                        ring[y][i - 1] = 1;
                        get_group[group[x][y]][i - 1] = 1;
                        dfs(step + 1);
                        value[x][y] = 0;
                        row[x][i - 1] = -1;
                        ring[y][i - 1] = -1;
                        get_group[group[x][y]][i - 1] = -1;
                    }
                }
            }
        }
    }
    
    public static void main(String[] args) {
        Gongge test = new Gongge();
        test.init();
        Scanner in = new Scanner(System.in);
        for(int i = 0;i < 9;i++) {
            String s = in.next();
            for(int j = 0;j < s.length();j++) {
                int t = s.charAt(j) - '0';
                value[i][j] = t;
                if(t != 0) {
                    row[i][t - 1] = 1;
                    ring[j][t - 1] = 1;
                    get_group[group[i][j]][t - 1] = 1;
                }
            }
        }
        test.dfs(0);
    }
    

    }

    6.测试结果图

    静态测试

    7.性能测试

    用一个微笑来表达现在的心情,哦耶~

    8.总结与评价

    对不起,我是个菜鸟,真的好多地方不会。多亏同学的指导和百度的帮助。我太菜了,不过好歹对GitHub熟悉了点,性能优化测试都不熟。不过,只要动手就一定会有收获的,加油吧,骚年。期待超越以前的自己,努力学习更多的知识吧。

    学号 作业头 github项目地址 代码分析 PSP表格 解题思路描述 设计实现过程 改进程序性能 代码说明 总结 总分
    20177685 2 1 1 1 0.5 0.5 0.5 0.5 1 8
  • 相关阅读:
    JS 格林威治时间格式(GMT)格式化
    SQL Server各个版本功能比较
    SQL Server各个版本功能比较
    SQL Server各个版本功能比较
    SQLl中的left join、right join、inner join详解
    SQLl中的left join、right join、inner join详解
    SQLl中的left join、right join、inner join详解
    【必备】jQuery性能优化的38个建议
    Metasploit笔记
    SpringBoot开发二十-Redis入门以及Spring整合Redis
  • 原文地址:https://www.cnblogs.com/asdfzx/p/12592323.html
Copyright © 2011-2022 走看看