func_code_string: #include <bits/stdc++.h>   using namespace std;   int dy[] = {-1, 1, 0, 0};   int dx[] = {0, 0, -1, 1};   int n, m;   char mp[1005][1005];   int k;   pair<int, int> p[30];   int row[1005][1005];   int col[1005][1005];   pair<int, int> d[100005];   int return_dir(char dir) {     if (dir ==  N )       return 0;     else if (dir ==  S )       return 1;     else if (dir ==  W )       return 2;     else       return 3;   }   int main() {     for (int i = 0; i < 30; i++) p[i].first = -1;     char ch;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         ch = getchar();         while (ch == 32 || ch ==   n ) ch = getchar();         mp[i][j] = ch;         if (mp[i][j] >=  A  && mp[i][j] <=  Z )           p[mp[i][j] -  A ] = make_pair(i, j);       }     }     int c = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mp[i][j] ==  # )           c++;         else           row[i][j] = c;       }     }     c = 0;     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         if (mp[i][j] ==  # )           c++;         else           col[i][j] = c;       }     }     scanf( %d , &k);     for (int i = 0; i < k; i++) {       string s;       cin >> s;       int a;       cin >> a;       d[i].first = return_dir(s[0]);       d[i].second = a;     }     bool was = false;     for (int i = 0; i < 30; i++) {       if (p[i].first == -1) continue;       bool ok = true;       int si = p[i].first;       int sj = p[i].second;       for (int j = 0; j < k; j++) {         int ni = si + dy[d[j].first] * d[j].second;         int nj = sj + dx[d[j].first] * d[j].second;         if (ni >= n || nj >= m || ni < 0 || nj < 0) {           ok = false;           break;         }         if (d[j].first < 2) {           if (col[ni][nj] != col[si][sj] || mp[ni][nj] ==  # ) ok = false;         } else {           if (row[ni][nj] != row[si][sj] || mp[ni][nj] ==  # ) ok = false;         }         si = ni;         sj = nj;       }       if (ok) {         was = true;         putchar( A  + i);       }     }     if (!was) cout <<  no solution ;     return 0;   }   