Cod sursa(job #1089216)

Utilizator SCBbestofSocaciu-Cumpanasu Bogdan SCBbestof Data 21 ianuarie 2014 16:24:00
Problema Zota & Chidil Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.92 kb
#include <iostream>
#include <bitset>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream f("zc.in");
ofstream g("zc.out");

int main()
{

    int N,M,x,y;
    f>>N>>M;
    //char *directii = (char*)malloc(M*sizeof(char));
    bool X[10000][10000];
    for(int i = 0; i < N; ++i)
    {
        f>>x>>y;

        X[x][y]=1;
        X[x+1][y]=1;
        X[x][y+1]=1;
        X[x+2][y]=1;
        X[x][y+2]=1;
        X[x+1][y+1]=1;
        X[x+1][y-1]=1;
        X[x-1][y+1]=1;
        X[x-1][y-1]=1;
        X[x-1][y]=1;
        X[x][y-1]=1;
        X[x-2][y]=1;
        X[x][y-2]=1;
    }

    x = 0;
    y = 0;
    char directie;
    int total=0;
    int distanta;
    for(int i = 0; i < M; ++i)
    {
        f>>directie>>distanta;
        switch(directie)
        {
            case 'N':
            {
                for(int j = 1 ; j<= distanta; ++j)
                {
                    if(X[x][y+j]==1)
                        ++total;
                }
                y+=distanta;
                break;
            }
            case 'S':
            {
                for(int j = 1 ; j<= distanta; ++j)
                {
                    if(X[x][y-j]==1)
                        ++total;
                }
                y-=distanta;
                break;
            }
            case 'E':
            {
                for(int j = 1 ; j<= distanta; ++j)
                {
                    if(X[x+j][y]==1)
                        ++total;
                }
                x+=distanta;
                break;
            }
            case 'V':
            {
                for(int j = 1 ; j<= distanta; ++j)
                {
                    if(X[x-j][y]==1)
                        ++total;
                }
                x-=distanta;
                break;
            }
        }
    }
    g<<total;
    return 0;
}