请帮忙 !这是我八皇后节目的来源,但是.. [英] Please help ! it's my eight queen program source but..

查看:107
本文介绍了请帮忙 !这是我八皇后节目的来源,但是..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个源代码.但是我的教授要我使用堆栈,数组和结构(位置x,位置y,queen的数字)编写代码.

我无法将此来源更改为我的教授想要的来源.

请帮我 .

对我来说很难..请帮助!

i wrote this source.but my prof want me to write code using stack,array and structure(position x, position y,queen''s numbers).

i can''t change this source to a source that my professor want to.

please help me .

it is very difficut to me ..please help!

#include <stdio.h>
#include <math.h>


#define SIZE 8

int stack[SIZE];
int count=0;


int find_place(int row);
int fill_block(int row);

int main(void)
{
    fill_block(0);

    return 0;
}



display()
{

    int row,col;
    printf("\n");
    printf("-----------",++count);
    for (row = 0; row < SIZE; row++)
    {
        for (col = 0; col< SIZE; col++)
        {
            if(stack[row]==col)printf(" Q ");
            else               printf(" _ ");
        }
        printf("\n");
    }
}


find_place(int row)
{

    for (int j = 0; j < row; j++)

    {

        if (abs(stack[row] - stack[j]) == (row - j) || (stack[j] == stack[row]) )

        {

            return 0;

        }

    }

    return 1;
}

fill_block(int row)
{

    if (row == SIZE) {

        display();

    }
    else {

        for (int i = 0; i < SIZE; i++) {

            stack[row] = i;

            if (find_place(row))

                fill_block(row+1);

  }


    }
    return -1;
}

推荐答案

gsfresh写道:
gsfresh wrote:

我无法更改此设置来源到我的教授想要的来源.

i can''t change this source to a source that my professor want to.



然后,您将失败.如果我们完成了功课,而您却避免了学习这些东西的机会,那么您将如何进行下一个作业?为什么不与老师交谈,读书,以及如果其他所有方法都失败了,您将面临无法编程和更改课程的麻烦?首先,您应该与您的教授交谈,索取参考资料,然后自己做.



Then you are going to fail. If we did your homework, and you avoided the chance to learn these things, how would you do the next assignment ? Why not talk to the teacher, read a book, and, if all else fails, face that you can''t program and change courses ? In the first instance, you should talk to your prof, ask for references, and do your own work.


这篇关于请帮忙 !这是我八皇后节目的来源,但是..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆