SRM455 Div2 Easy(250) SpidersOnTheGrid

SpidersOnTheGrid

#include <string>
#include <vector>

using namespace std;

class SpidersOnTheGrid
{
public:
    int find( vector <string> A );
};

int SpidersOnTheGrid::find( vector <string> A )
{
    int w = (int)A[0].size();
    int h = (int)A.size();

    vector<string> c( h+2, string( w+2, 'o' ) );

    for ( int y=0; y<h; y++ )
    for ( int x=0; x<w; x++ )
    switch ( A[y][x] )
    {
        case 'N':  c[y-1+1][x  +1] = 'x';  break;
        case 'E':  c[y  +1][x+1+1] = 'x';  break;
        case 'S':  c[y+1+1][x  +1] = 'x';  break;
        case 'W':  c[y  +1][x-1+1] = 'x';  break;
    }

    int n = 0;
    for ( int y=1; y<h+1; y++ )
    for ( int x=1; x<w+1; x++ )
    if ( c[y][x] == 'o' )
        n++;

    return n;
}