F - President's Office

来源:互联网 发布:直通车钻展淘宝客 编辑:程序博客网 时间:2024/05/16 09:21
F - President's Office
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.

The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.

Input

The first line contains two separated by a space integer numbers nm (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.

Output

Print the only number — the amount of President's deputies.

Sample Input

Input
3 4 RG.B..RR.TTT.
Output
2
Input
3 3 Z....H...Z
Output
0
#include<iostream>#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <vector>#include <bitset>#include <cstdio>#include <string>#include <numeric>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#include <functional>using namespace std;typedef long long ll;#define Exp 1e-8#define inf 0x7fffffff#define Read freopen("in.txt","r",stdin)#define Write freopen("out.txt","w",stdout)#define maxn 55#define mod 1000000007int main(){   int M,N;   int m[300]={0};           //字母的ASCII码-‘A’,作为下标   char c,Map[300][300]={0};//办公室用Map储存   scanf("%d%d %c",&M,&N,&c);   getchar();             for(int i=1;i<=M;i++)   {       for(int j=1;j<=N;j++)           scanf("%c",&Map[i][j]);       getchar();   }for(int i=1;i<=M;i++)//遍历每个角落   {       for(int j=1;j<=N;j++)       {           if(Map[i][j]==c)//找到President 的办公桌           {               int mc;               mc=Map[i-1][j]-'A';//前面的位置               m[mc]++;            //记录对应字母的数量               mc=Map[i][j-1]-'A';//左边的位置               m[mc]++;            //记录对应字母的数量               mc=Map[i+1][j]-'A';//后面的位置               m[mc]++;            //记录对应字母的数量               mc=Map[i][j+1]-'A';//右面的位置               m[mc]++;            //记录对应字母的数量           }       }   }int s=0;   for(int i=0;i<26;i++)       if(m[i]&&i!=c-'A')  //统计有多少个字母被记录           s++;       cout<<s<<endl;  //这就是助手的人数       return 0;}


原创粉丝点击