栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1208 Roll the Die!

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1208 Roll the Die!

#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<queue>#define ZUO 3#define YOU 0#define QIAN 2#define HOU 1using namespace std;int dir[4][2] = {1,0,0,1,0,-1,-1,0};//4个方向char s[300];int dui[7] = {0,6,5,4,3,2,1};int ok[7][7] = {{0},    {0,0,4,2,5,3,0},    {0,3,0,6,1,0,4},    {0,5,1,0,0,6,2},    {0,2,6,0,0,1,5},    {0,4,0,1,6,0,3},    {0,0,3,5,2,4,0}};//top&front,这个表的意义就是当top=i,front=j时候left的值是ok[i][j]struct node{    int top,front;    int left,right;    int back,bottom;    int x,y;}t;node roll( node t,int i)//以第i的方向,对t进行滚动{    int m;    t.x += dir[i][0];    t.y += dir[i][1];    if( i == QIAN )    {        m = t.front;        t.front = t.top;        t.top = t.back;        t.back = t.bottom;        t.bottom = m;    }    if( i == YOU )    {        m = t.right;        t.right = t.top;        t.top = t.left;        t.left = t.bottom;        t.bottom = m;    }    if( i == ZUO )    {        m = t.right;        t.right = t.bottom;        t.bottom = t.left;        t.left = t.top;        t.top = m;    }    if( i == HOU )    {        m = t.bottom;        t.bottom = t.back;        t.back = t.top;        t.top = t.front;        t.front = m;    }    return t;}int main(void){    //freopen("C:\Users\thinkpad\Desktop\out.txt","w",stdout);    int a,b;    char c;    printf("Problem 2 by team xn");    while( scanf("%d%d",&a,&b) != EOF )    {        printf("n");        if( !ok[a][b] )        { gets(s); printf("Invalid initial orientation:"); printf("     top = %d  front = %dn",a,b); continue;        }        printf("Initial orientation:");        printf("  top = %d  front = %dn",a,b);        printf("Moves:");        t.top = a;        t.front = b;        t.bottom = dui[ t.top ];        t.back = dui[ t.front ];        t.left = ok[ t.top ][ t.front ];        t.right = dui[ t.left ];        t.x = t.y = 0;        while( 1 )        { if( (c=getchar()) == 'n' ) break; c = getchar(); printf(" %c",c); switch(c) {     case 'E':t = roll(t,YOU);break;     case 'N':t = roll(t,HOU);break;     case 'W':t = roll(t,ZUO);break;     case 'S':t = roll(t,QIAN);break;     default :break; }        }        printf("nFinal orientation and position:");        printf("  top = %d  front = %d  x =%4d  y =%4dn",     t.top,t.front,t.x,t.y);    }    printf("End of problem 2 by team xn");    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371391.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号