标题:★☆机器人坐标变换问题☆★
只看楼主
随心
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:12
帖 子:2577
专家分:250
注 册:2007-8-12
得分:0 
代码都出来了,改成C程序应该不是什么难事吧?
多动一点脑子不是坏事

天之道,利而不害。圣人之道,为而不争。信言不美,美言不信。善者不辩,辩者不善。知者不博,博者不知。
2008-04-10 13:16
永夜的极光
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2721
专家分:1
注 册:2007-10-9
得分:0 
我的想法和6#相同
#include<stdio.h>
#include <conio.h>
int main()
{
    int x=0,y=0,offset[4][2]={0,1,1,0,0,-1,-1,0},direction=0,order;
    char dir_name[4][6]={"Up","Right","Down","Left"};
    printf("****************************************************\n");
    printf("**               Robot Move                       **\n");
    printf("**                                                **\n");
    printf("**             Input Your Order                   **\n");
    printf("**               -1 Turn Left                     **\n");
    printf("**               -2 Turn Right                    **\n");
    printf("**              n>0 Move Forward n step(s)        **\n");
    printf("**                0 Exit                          **\n");
    printf("****************************************************\n");
    printf("Now Position:  X:%d,Y:%d   Direction:%s\n",x,y,*(dir_name+direction));
    do
    {
        scanf("%d",&order);
        if(order == -1)
            direction = (direction + 3) % 4;
        if(order == -2)
            direction = (direction + 1) % 4;
        if(order > 0)
        {
            x += offset[direction][0] * order;
            y += offset[direction][1] * order;
        }
        printf("Now Position:  X:%d,Y:%d   Direction:%s\n",x,y,*(dir_name+direction));
    }while(order != 0);
    printf("Robot Stop!!\nFinal Position:  X:%d,Y:%d   Direction:%s\n",x,y,*(dir_name+direction));
    printf("Press Any Key to Exit");
    getch();
    return 0;
}

从BFS(Breadth First Study)到DFS(Depth First Study)
2008-04-10 13:20
xmfbit
Rank: 2
等 级:论坛游民
帖 子:3
专家分:12
注 册:2013-10-20
得分:0 
程序代码:
//用一个angle变量表示转过的角度,对4取余
#include <stdio.h>
int main()
{
    int x=0;
    int y=0;
    int command=0;
    int angle=0;    //angle表示转过的角度是90的angle倍
    while (scanf_s("%d",&command)!=0)
    {
        if (command==0)
        {
            break;
        }

        else
        {
            switch(command)
            {
            case -2:
                angle+=3;
                break;
            case -1:
                angle++;
                break;
            default:
                switch(angle%4)
                {
                case 0:
                    x+=command;
                    break;
                case 1:
                    y+=command;
                    break;
                case 2:
                    x-=command;
                    break;
                case 3:
                    y-=command;
                    break;
                default:
                    break;
                }
                break;
            }
        }
    }
    printf("%d %d\n",x,y);
    return 0;   

}
2013-10-20 16:45
mkmk30
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2011-10-28
得分:0 
C++写的!不错厉害啊!学习学习!
2015-05-10 11:10



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-208161-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.344986 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved