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. 如何用java完成一个中文词频统计程序

    要想完成一个中文词频统计功能,首先必须使用一个中文分词器,这里使用的是中科院的.下载地址是http://ictclas.nlpir.org/downloads,由于本人电脑系统是win32位的,因此下 ...

  2. LDA线性判别分析(转)

    线性判别分析LDA详解 1 Linear Discriminant Analysis    相较于FLD(Fisher Linear Decriminant),LDA假设:1.样本数据服从正态分布,2 ...

  3. python爬取酒店信息练习

    爬取酒店信息,首先知道要用到那些库.本次使用request库区获取网页,使用bs4来解析网页,使用selenium来进行模拟浏览. 本次要爬取的美团网的蚌埠酒店信息及其评价.爬取的网址为“http:/ ...

  4. Java http请求工具类

    该工具类可以调用POST请求或者Get请求,参数以Map的方式传入,支持获获取返回值,返回值接收类型为String HttpRequestUtil.java package com.util; imp ...

  5. Java String和StringBuffer和StringBuilder

    最近在牛课网上做了几道字符串操作的题目,好久没有做题了,之前用的也是大一时C语言做的,对Java字符串操作不太了解,所以深入了解一下String类的相关用法 String构造方法 String() 空 ...

  6. UML中的关联,泛化,依赖,聚集,组合(转)

    转自:http://blog.sina.com.cn/s/blog_5f8b45f20100dzjo.html 关联(association): 这是一种很常见的关系,这种关系在我们的生活中到处可见, ...

  7. JavaScript 中this的实现原理

    学懂 JavaScript 言语,一个标志就是了解下面两种写法,或许有不一样的成果. <blockquote "=""> var obj = { foo: f ...

  8. linux下访问window的共享文件,在命令行实现方法

    1.挂载共享目录 mount -t cifs //192.168.0.1/aa  /tmp/export -o username=text,password=test //192.168.0.1/aa ...

  9. codeblocks17.12 不能启动调试器

    调试器需要手动指定. settings->debugger->default->executable path.这里默认空的,需要指定.路径在安装目录下的CodeBlocks\Min ...

  10. PAT L2-011 玩转二叉树(二叉树层序遍历)

    给定一棵二叉树的中序遍历和前序遍历,请你先将树做个镜面反转,再输出反转后的层序遍历的序列.所谓镜面反转,是指将所有非叶结点的左右孩子对换.这里假设键值都是互不相等的正整数. 输入格式: 输入第一行给出 ...