0016 - Treasure Hunt / AizuOnlineJudge

問題 : 宝探し | Aizu Online Judge

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

double x=0.0, y=0.0;
int angle=90;

void Solve(int step, int turn)	{
	x+=step*cos( angle*(M_PI/180.0) );
	y+=step*sin( angle*(M_PI/180.0) );
	angle-=turn;
}

int main(void)	{
	int step, turn;

	while (scanf ("%d,%d", &step, &turn) && (step || turn) )
		Solve(step,turn);
	cout << (int)x << endl << (int)y << endl;
	return 0;
}

最初は北に向いていることから、角度は90度。
そこから、歩数と角度を三角関数を用いて算出。
sinとcosはラジアン角で計算するため、ラジアンへ変換。
最後にxとyの座標を出力。
~了~