Software Engineering 2019 third operation

GitHub address

https://github.com/Aurora-gloam/031702411

topic

Baidu Encyclopedia Description:
Sudoku is a disk nine palaces, each palace is divided into nine small cell. Given certain conditions known digital and solving this eighty-one grid, using logic and reasoning, enter the number 1-9 on the other spaces. 1-9 so that each number appears only once in each row, each column and each palace, also known as "squares."
Implement a command line program, which may be called Sudoku.

PSP table

PSP2.1 Personal Software Process Stages It is expected to take (minutes) The actual time-consuming (minutes)
Planning Program (this task requires much time estimate) 60 60
Development Develop 905 785
Analysis Needs analysis (including learning new technologies) 120 90
Design Spec Generate design documents 60 30
Design Review Design Review 30 10
Coding Standard Code specifications (development of appropriate norms for the current development) 5 5
designed Specific design 60 40
Coding Specific coding 480 360
Code Review Code Review 30 10
Test Test (self-test, modify the code, submit modifications) 120 240
Reporting report 290 230
test repor testing report 30 30
Size Measurement Computing workload 20 20
Postmortem&Process Improvement Plan Hindsight and propose process improvement plan 240 180
total 1255 1075

Problem-solving ideas

  A job requirement is beginning to see the stops alone , I thought I would first of all how to solve a Sudoku. I should need to fill in the spaces where the value of the line in, that column, which appeared in that house to see numbers that can be excluded from the possibility to fill in. Then select the remaining numbers can fill a fill first, and then consider the next need to fill a number of blank, the process of considering the same as the last. It has been the case until all spaces filled out, or can be filled without numbers appear. If the line where the spaces, columns, Palace has all the numbers appear, then back to fill in the blanks on a digital fill other numbers can be filled. Then followed a downward spaces to fill. If you fill out all the spaces. Then solving this Sudoku. Then I wanted my program to be able to make itself independent in accordance with the same way.

Design ideas

  • First, build a class sudoku represents only the disk we need to fill in the spaces, the spaces where the line contains Row , row COL , may fill in the value Val , the number of possible digital sum is set and the corresponding data members and access function.
  • Secondly, the design of a space to see where the rows, columns, there have been a function of the palace numbers the Check . An array with a stored result, the array index value indicating the occurrence of numbers, numerals array represents the number represented by the lower occur.
  • Once again, return to the previous design a space to re-fill function numbers the Back . Of the class sum is judged, if it is filled with a variety of possible stored val ; otherwise continue to call back function.
  • Finally, the definition of a two-dimensional array su store a Sudoku disk. The class object S , a two-dimensional array to store the disk su as well as the emergence of digital storage array a set of global variables.

Code Description

1. Deliverable sudoku

class sudoku
{
private:
    int row;
    int col;
    int sum;// 为val数组可达到的最大下标 
    int val[9];
public:
    void setrow_col(int r, int c);
    void setsum();
    void setval_sum(int num);
    int getval(int t);
    int getsum();
    int getrow();
    int getcol();
};
void sudoku::setrow_col(int r, int c)//对数据成员行、列进行赋值 
{
    col = c;
    row = r;
}
void sudoku::setsum()//每回到一次此空格重新填入,数值减1 
{
    sum = sum - 1;
}
void sudoku::setval_sum(int num)//将该空格可能的数值填入val数组中 ;num为数独阶数  
{
    int i, j = 0;
    for (i = 1; i <= num; i++)
    {
        if (a[i] == 0)
        {
            val[j] = i;
            j++;
        }
    }
    sum = j - 1;
}
//获取数据成员
int sudoku::getval(int t)
{
    return val[t];
}
int sudoku::getsum()
{
    return sum;
}
int sudoku::getcol()
{
    return col;
}
int sudoku::getrow()
{
    return row;
}

2. Check the numbers in function check

//遍历该空格所在行、列、宫中出现的数
//su是全局变量,一个二维数组,用来存放数独盘面。
void cheak(int r,int c,int num)//r是所在行号,c是所在列号,num是数独盘面的阶数
{
    int i,j,x,y;
    for(i=0;i<10;i++)//a数组中存放下标所示数字在行、列、宫中出现的次数;每对一个空格查看出现过的数,需要对数组重置为0
    {
        a[i]=0;
    }
    for(i=0;i<num;i++)//查看所在行出现的数 
    {
        if(su[r][i]!=0)
        a[su[r][i]]=a[su[r][i]]+1;
    } 
    for(i=0;i<num;i++)//查看所在列出现的数 
    {
        if(su[i][c]!=0)
        a[su[i][c]]=a[su[i][c]]+1;
    } 
//查看所在宫出现的数
//x,y是用来标识空格所在宫的位置
    if(num==4) 
    {
        x=r/2;
        y=c/2;  
        for(i=x*2;i<=(x*2+1);i++)
        {
            for(j=y*2;j<=(y*2+1);j++)
            {
                if(su[i][j]!=0)
                a[su[i][j]]=a[su[i][j]]+1;
            }
        }
    } 
    else if(num==6)
    {
        x=r/2;
        y=c/3;  
        for(i=x*2;i<=(x*2+1);i++)
        {
            for(j=y*3;j<=(y*3+2);j++)
            {
                if(su[i][j]!=0)
                a[su[i][j]]=a[su[i][j]]+1;
            }
        }       
    }
    else if(num==8)
    {
        x=r/4;
        y=c/2;  
        for(i=x*4;i<=(x*4+3);i++)
        {
            for(j=y*2;j<=(y*2+1);j++)
            {
                if(su[i][j]!=0)
                a[su[i][j]]=a[su[i][j]]+1;
            }
        }       
    }
    else if(num==9)
    {
        x=r/3;
        y=c/3;  
        for(i=x*3;i<=(x*3+2);i++)
        {
            for(j=y*3;j<=(y*3+2);j++)
            {
                if(su[i][j]!=0)
                a[su[i][j]]=a[su[i][j]]+1;
            }
        }       
    }
 } 



Where the query of the Palace of digital thinking has occurred is to determine the location of the Palace of the space is located, and then start looking from the first grid Palace and note the number that appears. The first grid position of the space where the palace by dividing grids specifications, then multiply the quotient obtained scale grids, such as the Palaces grid is x = r / 2, y = c / 3; spaces where the first house a grid position 2 X,. 3 Y, of the order house other similar operations. As shown below,

3. Fill function back again next possible value

int back(int t)//重置该空格的值 
{
    if(s[t].getsum()>=0)//判断该空格是否还有其他未填入可能数字。若有,填入该值且该空格可能数字个数减1;若无,将本格中数字置0,继续调用back函数回到上一个空格。
    {
        su[s[t].getrow()][s[t].getcol()]=s[t].getval(s[t].getsum());
        s[t].setsum(); 
    } 
    else
    {
        su[s[t].getrow()][s[t].getcol()]=0;
        t=back(t-1);
    }
    return t;
}

operation result

The use of teaching assistants collected Sudoku Sudoku disk and disk to find yourself on the network, enter the following results:

Performance Analysis

Mentality and harvest

  After this personal programming job, I learned a lot. Learn the command line parameters passed to the main function, I learned to read the file operation, learned to upload files on GitHub ...... now he still needs to learn a lot of things, but also efforts can . Come on!

Guess you like

Origin www.cnblogs.com/address2019/p/11567164.html