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. C#整数的三种强制类型转换int、Convert.ToInt32()、int.Parse()的区别

    .int适合简单数据类型之间的转换,C#的默认整型是int32(不支持bool型): .int.Parse(string sParameter)是个构造函数,参数类型只支持string类型: .Con ...

  2. qt 中的基本知识

    1. 由 .ui 文件生成界面头文件: uic -o ui_dialog.h dialog.ui 2. 在工程目录下生成与平台无关的工程文件 : qmake -project 3. 生成与平台相关的  ...

  3. uigetfile的用法(批量读取图片)

    matlab编程中有时想调入电脑中的某个文件,现找到了一些关于uigetifile用法~~[filename, pathname] = uigetfile( ...    {'*.jpg;*.tif; ...

  4. sqlite3调试

    [sqlite3调试] 1.adb shell 激活模拟器shell. 2.cd /data/data/com.xxx.xxx/databases 进入app 数据库目录. 3.ls 查看有哪些数据库 ...

  5. sql语句where条件判断是否是相同的string时 原来不判断大小写

    SELECT * from api_check where api ="Worker" SELECT * from api_check where api ="worke ...

  6. sqlmap自动注入

    基于python2.7开发 git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev

  7. http4e eclipse plugin 插件介绍

    感谢作者的分享: http://blog.csdn.net/wiker_yong/article/details/10066905 以及作者的破解jar.目前看网站留言说已经git了. 官网链接地址: ...

  8. django admin后台显示中文

    在settings中设置 LANGUAGE_CODE = ‘zh-Hans’

  9. 【Scheme】cons的过程性实现

    (define (cons x y) (define (dispatch m) (cond ((= m 0) x) ((= m 1) y))) dispatch) (define (car z) (z ...

  10. PHP 获取 IE浏览器版本号

    function getIEBrowserVersion(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); if(strpos($agent, ...