Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created October 26, 2014 13:46
Show Gist options
  • Save henrybear327/71b1843a9cf77018fa9d to your computer and use it in GitHub Desktop.
Save henrybear327/71b1843a9cf77018fa9d to your computer and use it in GitHub Desktop.
ACM10409(using define).c
#include <stdio.h>
#include <stdlib.h>
#define north 2
#define south 3
#define east 0
#define west 1
#define top 4
#define bottom 5
/*
http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&page=show_problem&category=&problem=1350&mosmsg=Submission+received+with+ID+14394659
*/
/*
Debugging experience...
If the answer appears to be right all the time, check the ENTIRE algorithm again. Two hours were spent on debugging a trivial typo bug in the code...
*/
int main()
{
int total_steps, steps;
while(scanf("%d", &total_steps) == 1 && total_steps)
{
int dice[6] = {4,3,2,5,1,6};
for(steps = 1; steps <= total_steps; steps++)
{
char string[6];
scanf("%s", &string);
int dice_tmp[6], i;
for(i = 0; i <= 5; i++)
{
dice_tmp[i] = dice[i];
}
if(string[0] == 'n')
{
dice[bottom] = dice_tmp[north];
dice[south] = dice_tmp[bottom];
dice[top] = dice_tmp[south];
dice[north] = dice_tmp[top];
}
if(string[0] == 's')
{
dice[north] = dice_tmp[bottom];
dice[top] = dice_tmp[north];
dice[south] = dice_tmp[top];
dice[bottom] = dice_tmp[south];
}
if(string[0] == 'e')
{
dice[east] = dice_tmp[top];
dice[bottom] = dice_tmp[east];
dice[west] = dice_tmp[bottom];
dice[top] = dice_tmp[west];
}
if(string[0] == 'w')
{
dice[top] = dice_tmp[east];
dice[west] = dice_tmp[top];
dice[bottom] = dice_tmp[west];
dice[east] = dice_tmp[bottom];
}
}
printf("%d\n", dice[4]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment