# Third software engineering jobs

The third number of jobs in software engineering alone

List items

Tags (separated by spaces): Unclassified


Github project Address: https://github.com/jjsgxty/031702510

PSP table

PSP2.1 Personal Software
Process Stages
Estimated time consuming (min) The actual consuming (min)
Planning plan 50 30
Estimate Estimate how much time this task requires 50 30
Development Develop 240 300
Analysis Needs analysis
(including learning new technologies)
120 180
Design Spec Generate design documents 60 30
Design Review Design Review 30 20
Coding Standard Code specifications
(development of appropriate norms for the development)
30 20
Design Specific design 60 60
Coding Specific coding 240 180
Code Review Code Review 180 120
Test Test
(self-test, modify, commit the changes)
180 180
Reporting report 60 60
Test Report testing report 20 20
Size Measurement Computing workload 10 10
Postmortem & Process< Later summarized, and process improvement plan 60 60

Problem-solving process

Just beginning to see time job, think DFS can use recursion to achieve job requirement is to achieve 3 to 9 grids, I would like to complete the squares, then the other grids further changed on it, and then I began Jiugongge code.
1. Deep search constructor alone, respectively, is determined in each grid numbers are filled correctly, if the current cell is not empty skip
2. Fill determined number is correct, the first row is determined, and then determines the columns Finally, judging each small grids
3. after all conform to exit the recursive

After the completion of the implementation squared, I found trouble is cmd command-line arguments, the beginning is really ignorant, not command line parameters, file streams do not know, read the contents of the book about c ++ file stream input and output will be use file stream, but a bunch of cmd line parameters Baidu still do not understand what it meant, the last resort, a student, was finally thoroughly understand roughly

Then is the complement of the other grids, grids 3,5,7 relatively simple, only need to determine each column of each row, so I 4,6,8,9 put together, from all grids of squares to process I often forget to change in some parts of the details of each find all find annoying, and I in a test grids are correct output when the input file will misplace to other grids in the input file, looking for a long file problem turned out to be wrong. Well, still I want to be able to carefully some of it ┭┮﹏┭┮

Check function

   //判断shu填入n时是否满足条件

bool Check(int n, int shu)
{
    //判断n所在横列是否合法 
    for (int i = 0; i < siz; i++)
    {
        int j = n / siz;    // j为n竖坐标
        if (num[j][i] == shu) return false;
    }

    //判断n所在竖列是否合法 
    for (int i = 0; i < siz; i++)
    {
        int j = n % siz;    //j为n横坐标 
        if (num[i][j] == shu) return false;
    }
    if (siz == 4 || siz == 6 || siz == 8 || siz == 9)
    {
        int a, b;   //a为每个小宫格中横向的格子数,b为纵向格子数 
        switch (siz)
        {
        case 4:
            a = 2, b = 2;
            break;
        case 6:
            a = 3, b = 2;
            break;
        case 8:
            a = 2, b = 4;
            break;
        case 9:
            a = 3, b = 3;
            break;
        }
        int x = n / siz / b * b;     //x为n所在的小宫格左顶点竖坐标

        int y = n % siz / a * a;     //y为n所在的小宫格左顶点横坐标


        //判断n所在的小宫格是否合法 
        for (int i = x; i < x + b; i++)
        {
            for (int j = y; j < y + a; j++)
            {
                if (num[i][j] == shu) return false;
            }
        }
    }
    return true;    //都合法,返回正确

}

DFS function

//深搜构造数独 
int DFS(int n)
{
    int amount = 0;
    switch (siz)
    {
    case 3:
        amount = 8;
        break;
    case 4:
        amount = 15;
        break;
    case 5:
        amount = 24;
        break;
    case 6:
        amount = 35;
        break;
    case 7:
        amount = 48;
        break;
    case 8:
        amount = 63;
        break;
    case 9:
        amount = 80;
        break;
    }
    //所有的都符合,退出递归 

    if (n > amount)
    {
        sign = true;
        return 0;
    }

    //当前位不为空时跳过
    if (num[n / siz][n % siz] != 0)
    {
        DFS(n + 1);
    }

    else
    {
        //否则对当前位进行枚举测试 
        for (int i = 1; i <= siz; i++)
        {
            //满足条件时填入数字 
            if (Check(n, i) == true)
            {
                num[n / siz][n % siz] = i;
                DFS(n + 1);    // 继续搜索 

                 //返回时如果构造成功,则直接退出 
                if (sign == true) {
                    return 0;
                }

                //如果构造不成功,还原当前位 
                    num[n / siz][n % siz] = 0;
            }

        }

    }
    return 0;  //此处不加会有警告
}

The main function

int main(int argc, char* argv[])
{
    int k;
    char* in;  //输入文件 
    char* out;  //输出文件 
    int time;   //盘面数目 
    
    siz = atoi(argv[2]);  //atoi (ascii to integer)是把字符串转换成整形数的一个函数 
                       //头文件为 #include <stdlib.h> 
    time = atoi(argv[4]);
    
    in = argv[6];
    ifstream infile(in);
    out = argv[8];
    ofstream outfile(out);
    
    for (k = 0; k < time; k++) {
        char temp[10][10] = { 0 };
        int l = 0;
        for (int i = siz * k + k; i < siz * k + k + siz; i++)
        {
            for (int j = 0; j < siz; j++)
            {
                infile >> temp[i][j];
                num[l][j] = temp[i][j] - '0';   // 两个字符相减就是ASCII码之间的减法操作
            }

            l++;
        }
        cout << "\n";
        sign = false;    //此处注意一定要加!!!
        DFS(0);

        for (int i = 0; i < siz; i++)
        {
            for (int j = 0; j < siz; j++)
            {
                cout << num[i][j] << " ";
            }
            cout << "\n";
        }
        cout << "\n";  

        ofstream outfile;
        outfile.open("output.txt", ios::app);   //以后继方式打开文件以便继续写
        for (int i = 0; i < siz; i++) {
            for (int j = 0; j < siz; j++) {
                outfile << num[i][j] << " ";
            }
            outfile << endl;
        }
        outfile << "\n";
        outfile.close();
    }
}

Test Results

Guess you like

Origin www.cnblogs.com/jjsgxty/p/11588139.html