请将代码从C转换为C#... plzzzzz [英] kindly convert code from C to C# ...plzzzzz

查看:95
本文介绍了请将代码从C转换为C#... plzzzzz的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include "stdafx.h"
#include

int pairs(char *brd[],int r,int c)
{
    int attacks = 0;
    int tr;
    int tc;

    for(int cc=0;cc<8;cc++)
        attacks += ((cc!=c)&&(brd[r][cc]=='Q'))?1:0;

    for (int k=-7;k=0)&&(tr=0)&&(tc=0)&&(tr=0)&&(tc<8))
            if((tr!=r) && (tc!=c))
                  attacks += (brd[tr][tc]=='Q');

    }
    return(attacks);
}

int _tmain(int argc, _TCHAR* argv[])
{
    char *board[8];
    int *attackers[8];

    while(1)
    {
        for(int r=0;r<8;r++)        // main search loop
        {
            board[r] = new(char[8]);
            for(int c=0;c<8;c++) board[r][c] = ' ';
            attackers[r] = new(int[8]);
        }
        for(int c =0;c<8;c++)
        {
            int r = rand()%8;
            board[r][c] = 'Q';
        }

        int attempts = 0;
        while(attempts<10)
        {
            // number of attackers
            for(int r=0;r<8;r++)
                for(int c=0;c<8;c++)
                    attackers[r][c] = pairs(board,r,c);
            // if the sum of the attackers at the queen positions = 0; done
            int attacks =0;
            for(int r=0;r<8;r++)
                for(int c=0;c<8;c++)
                    attacks += (board[r][c]=='Q')?pairs(board,r,c):0;
            if (attacks == 0)
            {
            printf("\n FOUND ONE*********");    // Found a solution to the problem
                printf("\n Queens");
                // prints out the board
                for(int r=0;r<8;r++)
                {   printf("\n %d:",r);
                    for(int c=0;c<8;c++)
                        printf("%c",board[r][c]);
                }
                printf("\n");
                break;
            }

            // find min
            int min = 8;
            int minr=0;
            int minc=0;
            for(int r=0;r<8;r++)
                for(int c=0;c<8;c++)
                    if(attackers[r][c]<min)
                    {
                        min = attackers[r][c];
                        minr=r;
                        minc=c;
                    }

            // move the queen to that spot
            for(int r=0;r<8;r++)
                board[r][minc] = ' ';
            board[minr][minc] = 'Q';
            // dump the board
          attempts++;

        }
    }
    return 0;
}

推荐答案

否。

为什么不呢?有很多原因。
首先,因为C和C#是非常不同的语言,它们共享许多常见的语法:转换代码不会产生高质量的C#代码,因为有非常非常不同的框架所涉及的原则。

其次,因为我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!
No.
Why not? A number of reasons.
Firstly, because C and C# are very different languages which share a lot of common syntax: converting the code will not result in good quality C# code because there are very, very different frameworks and principles involved.
Secondly, because we do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


注意这些建议:将c源代码转换为c# [ ^ ]

底线是,你必须自己学习。
Heed these advices: conversion c source code to c#[^]
The bottom line is, you have got to learn to do it yourself.


8皇后带回溯C ++ [ ^ ]


这篇关于请将代码从C转换为C#... plzzzzz的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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