SRM473 Div1 Easy(250), Div2 Medium(500) SequenceOfCommands
コマンドを実行して、向きを変えているか移動していなければ良い。
#include <string> #include <vector> #include <numeric> using namespace std; class SequenceOfCommands { public: string whatHappens( vector <string> commands ); }; string SequenceOfCommands::whatHappens( vector <string> commands ) { string cmd = accumulate( commands.begin(), commands.end(), string() ); int x = 0; int y = 0; int d = 0; for ( string::iterator c=cmd.begin(); c!=cmd.end(); c++ ) { switch ( *c ) { case 'S': switch ( d ) { case 0: x--; break; case 1: y--; break; case 2: x++; break; case 3: y++; break; } break; case 'L': d = ( d + 3 ) % 4; break; case 'R': d = ( d + 1 ) % 4; break; } } if ( d != 0 || x == 0 && y == 0 ) return "bounded"; else return "unbounded"; }