Pagini recente » Cod sursa (job #3160727) | Cod sursa (job #2616388) | Cod sursa (job #2911041) | Cod sursa (job #2417788) | Cod sursa (job #1089216)
#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;
}