UVa : 11505 (Logo)


// http://uva.onlinejudge.org/external/115/11505.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <utility>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;


int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        int command;
        scanf ("%d", &command);

        double x = 0;
        double y = 0;
        double theta = 0;

        for ( int i = 0; i < command; i++ ) {
            string c;
            double m;

            cin >> c >> m;

            if ( c == "fd" ) {
                x += (m * cos (theta * pi / 180));
                y += (m * sin (theta * pi / 180));
                //theta = 0;
            }
            else if ( c == "lt" ) {
                theta += m;
                theta = fmod (theta, 360);
            }
            else if ( c == "rt" ) {
                theta -= m;
                theta = fmod (theta, 360);
            }
            else {
                x -= (m * cos (theta * pi / 180));
                y -= (m * sin (theta * pi / 180));
                //theta = 0;
            }
        }

        printf ("%0.lf\n", sqrt (x * x + y * y));
    }

    return 0;
}

// @END_OF_SOURCE_CODE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s