-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path59841657.cpp
72 lines (72 loc) · 1.56 KB
/
59841657.cpp
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
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
void addit(char c);
vector<char> data;
int main()
{
int n,m;
char boss;
cin>>n>>m>>boss;
int** arr=new int*[n];
for(int i=0;i<n;i++)
arr[i]=new int[m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
char a;
scanf("%c",&a);
if(a=='\n')
{
j--;
continue;
}
else
{
arr[i][j]=a;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(arr[i][j]==boss)
{
if(i>0)// up
{
if(arr[i-1][j]!=boss && arr[i-1][j]!='.')
addit(arr[i-1][j]);
}
if(i<n-1)// down
{
if(arr[i+1][j]!=boss && arr[i+1][j]!='.')
addit(arr[i+1][j]);
}
if(j>0)// left
{
if(arr[i][j-1]!=boss && arr[i][j-1]!='.')
addit(arr[i][j-1]);
}
if(j<m-1)// right
{
if(arr[i][j+1]!=boss && arr[i][j+1]!='.')
{
addit(arr[i][j+1]);
}
}
}
}
}
cout<<data.size()<<endl;
return 0;
}
void addit(char c)
{
for(int i=0;i<data.size();i++)
{
if(data[i]==c)
return;
}
data.push_back(c);
}