SRM523 Div2 Easy(250) AlphabetPath

AlphabetPath

#include <string>
#include <vector>
using namespace std;

class AlphabetPath{public:
string doesItExist( vector <string> letterMaze )
{
    int w = (int)letterMaze[0].size();
    int h = (int)letterMaze.size();

    int c = 0;
    for ( int y=0; y<h; y++ )
    for ( int x=0; x<w-1; x++ )
        if ( letterMaze[y][x]!='.' && letterMaze[y][x+1]!='.' &&
             abs(letterMaze[y][x]-letterMaze[y][x+1])==1 )
            c++;
    for ( int y=0; y<h-1; y++ )
    for ( int x=0; x<w; x++ )
        if ( letterMaze[y][x]!='.' && letterMaze[y+1][x]!='.' &&
             abs(letterMaze[y][x]-letterMaze[y+1][x])==1 )
            c++;

    return c==25 ? "YES" : "NO";
}};