Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vcgato29/127233fb0a26e2f51dafbe0ff66cd0ff to your computer and use it in GitHub Desktop.
Save vcgato29/127233fb0a26e2f51dafbe0ff66cd0ff to your computer and use it in GitHub Desktop.
B. President's Office-Codeforces
// working.cpp by Bill Weinman <http://bw.org/>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,check[27]={0},res=0;
char c,a[150][150];
cin>>n>>m>>c;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>a[i][j];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(a[i][j]==c)
check[a[i-1][j]-'A']=check[a[i+1][j]-'A']=check[a[i][j-1]-'A']=check[a[i][j+1]-'A']=1;
for(int i=0;i<=26;i++) res+=check[i];
cout<<res-check[c-'A']<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment