/
president's-office.cc
67 lines (55 loc) · 1.31 KB
/
president's-office.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* STATUS = ACCEPTED
*/
#include <cstdio>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stack>
#include <cstring>
#include <set>
#include <iostream>
using namespace std;
#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORE(it,c) for(__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define SZ(c) ((int)c.size())
int main()
{
#ifndef ONLINE_JUDGE
freopen("president's-office.in","r",stdin);
#endif
int n, m;
string str, c;
int dir[][2] = { {0,-1}, {0,1}, {-1,0}, {1,0} };
set<char> deputies;
getline(cin, str);
istringstream strin(str);
strin >> n >> m >> c;
vector<string> room(n);
FOR(i,n)
{
getline(cin, room[i]);
}
FOR(i,n)
{
FOR(j,m)
{
if(room[i][j] == c[0])
{
FOR(k, 4)
{
int ii = i + dir[k][0], jj = j + dir[k][1];
if((ii >= 0) && (ii < n) && (jj >= 0) && (jj < m))
{
if(room[ii][jj] != c[0] && room[ii][jj] != '.')
{
deputies.insert(room[ii][jj]);
}
}
}
}
}
}
printf("%d\n", deputies.size());
return 0;
}