struct Dice主程式內,讀入翻動次數 n 次後,先初始化骰子數字各在哪些方位:
{
int up, down, north, east, south, west;
};
struct Dice d;
d.up = 1, d.down = 6, d.north = 2,最後只要依照相對面的骰子總和為 7 以及空間概念,就可寫出來:
d.east = 4, d.south = 5, d.west = 3;
while (n --)
{
scanf("%s", str);
if (str[0] == 's') /* 南 */
d.south = d.up, d.up = d.north,
d.down = 7 - d.up, d.north = 7 - d.south;
if (str[0] == 'n') /* 北 */
d.down = d.north, d.north = d.up,
d.up = 7 - d.down, d.south = 7 - d.north;
if (str[0] == 'w')
d.down = d.west, d.west = d.up,
d.up = 7 - d.down, d.east = 7 - d.west;
if (str[0] == 'e')
d.east = d.up, d.up = d.west,
d.down = 7 - d.up, d.west = 7 - d.east;
}
printf("%d\n", d.up);
By David.K
p10409題目連結
回ACM題庫目錄
回首頁
沒有留言:
張貼留言