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 n, m (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.

Example

Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0

题意:找给出颜色周围有多少种不同颜色
 #include <iostream>
#include <stdio.h>
using namespace std;
int n, m;
char p;
char Map[][];
int col[];
int ans = ;
int dir[][] = {,,,,-,,,-}; void dfs(int x, int y){
for(int i = ; i < ; i ++){
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && xx < n && yy >= && yy < m){
if(col[Map[xx][yy]] == && Map[xx][yy] != '.'){
ans++;
col[Map[xx][yy]] = ;
}
}
}
} int main(){
cin >> n >> m;
getchar();
p = getchar();
col[p] = ;
for(int i = ; i < n; i++){
for(int j = ; j < m; j++){
cin >> Map[i][j];
}
}
for(int i = ; i < n; i++){
for(int j = ;j < m; j++){
if(Map[i][j] == p){
dfs(i,j);
}
}
}
cout << ans << endl;
}

President's Office的更多相关文章

  1. Codeforces Beta Round #6 (Div. 2 Only) B. President's Office 水题

    B. President's Office 题目连接: http://codeforces.com/contest/6/problem/B Description President of Berla ...

  2. CF6B President's Office 题解

    看到大致思路一致的题解,决定发一篇运用STL不用dfs的题解     好久不发题解,心里不爽 思路: 1.输入的同时找到总统桌子的位置,用vector<pair <int,int> ...

  3. CUGBACM Codeforces Tranning 3 题解

    链接:http://acm.hust.edu.cn/vjudge/contest/view.action? cid=62515#overview 描写叙述:第三场CF训练了.这次做的挺搞笑的,我记得这 ...

  4. 经济-AMA:百科

    ylbtech-经济-AMA:百科 美国市场营销协会(American Marketing Association,简称AMA)于1937年由市场营销企业界及学术界具有远见卓识的人士发起成立.如今,该 ...

  5. .NET Core 首例 Office 开源跨平台组件(NPOI Core)

    前言 最近项目中,需要使用到 Excel 导出,找了一圈发现没有适用于 .NET Core的,不依赖Office和操作系统限制的 Office 组件,于是萌生了把 NPOI 适配并移植到 .NET C ...

  6. [.NET] 打造一个很简单的文档转换器 - 使用组件 Spire.Office

    打造一个很简单的文档转换器 - 使用组件 Spire.Office [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/6024827.html 序 之前,& ...

  7. 高效而稳定的企业级.NET Office 组件Spire(.NET组件介绍之二)

    在项目开发中,尤其是企业的业务系统中,对文档的操作是非常多的,有时几乎给人一种错觉的是”这个系统似乎就是专门操作文档的“.毕竟现在的很多办公中大都是在PC端操作文档等软件,在这些庞大而繁重的业务中,单 ...

  8. 在禅道中实现WORD等OFFICE文档转换为PDF进行在线浏览

    条件: 安装好禅道的服务器 能直接浏览PDF的浏览器(或通过 安装插件实现 ) 文档转换服务程序(建议部署在另一台服务器上)     实现 原理: 修改禅道的文件预览功能(OFFICE文档其使用的是下 ...

  9. RMS:Microsoft Office检测到您的信息权限管理配置有问题。有关详细信息,请与管理员联系。(转)

    原文:https://zhidao.baidu.com/question/435088233.html RMS有两种方式: 1.使用微软的服务器,这个是连接到微软的服务器上面做权限控制,在今年5月份之 ...

随机推荐

  1. centos 安装mysql数据库

    在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1 下载并安装MySQL官方的 Yum Re ...

  2. hdu3579-Hello Kiki-(扩展欧几里得定理+中国剩余定理)

    Hello Kiki Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:

    1.centos7 系统,自带python2.7 ,我安装了python3.5 并设置为系统默认python ,yum 语法不支持 2.解决办法: ls /usr/bin | grep python选 ...

  4. Web App Manifest

    [Web App Manifest] The web app manifest provides information about an application (such as name, aut ...

  5. appium的兼容问题

    appium 和Android7.0的兼容问题 标签(空格分隔): appium 随着Android系统的不断的迭代更新,目前Android系统都已经更新到9.0系统了,有些小伙伴appium版本还是 ...

  6. veil-catapult

    veil-catapult进行payload投放,直接使payload在内存中执行. kaliIP:192.168.1.119 目标IP:192.168.1.121 1.powershell powe ...

  7. python--第三天总结

    [collection系列]1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能 c = Counter('abcdeabc ...

  8. SQLdeveloper同时显示多个表的窗口

  9. flash as3.0 截图保存图片

    import flash.display.MovieClip; import flash.events.MouseEvent; import flash.filesystem.*; ///////// ...

  10. slf4j + log4j 需要的依赖

    正确的依赖 <!-- slf4j 依赖包 --> <dependency> <groupId>org.slf4j</groupId> <artif ...