Problem 1210 : Die Game
Problem C: Die Game
http://rose.u-aizu.ac.jp/onlinejudge/ProblemSet/description.jsp?id=1210
- 問題概要
サイコロを東西南北に転がして、最後に上向いてる面の数字は?
- 解法
かくだけ。
- ソース
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<map> #include<set> #include<cstdlib> #include<cstdio> #include<cmath> #include<sstream> #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) #define ALL(C) (C).begin(),(C).end() #define pb push_back #define mp make_pair #define vint vector<int> #define FOR(it,o) for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it) #define lli long long int #define ld long double using namespace std; class Dice{ public: int n[6]; Dice(){ rep(i, 6)n[i] = i+1; } void roll(string s){ if(s == "north"){ int tmp = n[0]; n[0] = n[4]; n[4] = n[5]; n[5] = n[1]; n[1] = tmp; } if( s == "east"){ int tmp = n[0]; n[0] = n[2]; n[2] = n[5]; n[5] = n[3]; n[3] = tmp; } if( s == "south" ){ int tmp = n[0]; n[0] = n[1]; n[1] = n[5]; n[5] = n[4]; n[4] = tmp; } if( s == "west"){ int tmp = n[0]; n[0] = n[3]; n[3] = n[5]; n[5] = n[2]; n[2] = tmp; } } }; main(){ int n; while(cin >> n){ if(n == 0)break; Dice d; rep(i, n){ string s; cin >> s; d.roll(s); } cout << d.n[0] << endl; } }
読むまでが大変だよね。