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. 吴裕雄 python 爬虫(2)

    import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com' html = requests.get(url) ...

  2. python使用cv2显示图片像素值

    给定一张灰度图,显示这张图片的像素值 def show_image_pixel(img): ''' :param img: 需要输出像素值的图像,要求是灰度图 :return: 无返回值 ''' he ...

  3. mysql 数据导出

    windowos: select * from pj_zzspdz_fpmx  order by kprq desc LIMIT 0,1000000 into outfile 'd:\fpmx.xls ...

  4. 05_ssm基础(三)之Spring基础

    11.spring入门引导 12.spring_HelloWord程序 实现步骤: 0.找到spring压缩包,并解压 1.拷贝jar包 2.添加主配置文件(官方文档约28页) 3.在测试中使用 13 ...

  5. Bootstrap的aria-label和aria-labelledby

    [Bootstrap的aria-label和aria-labelledby] 用于盲人阅读的属性,基本也没什么用. 参考:http://blog.csdn.net/liuyan19891230/art ...

  6. CSS Media Query

    [CSS Media Query] CSS Media Queries are a feature in CSS3 which allows you to specify when certain C ...

  7. J_link重刷固件

    第一步:上电短接ERS 第二步:上电短接TST      (擦除原来的固件) 完成上面两步后,再连接电脑,电脑将出现正常的串口连接 第三步:(烧固件) 在SAM-BA xxx固件烧写选好芯片类型,连接 ...

  8. PropertyGrid控件动态生成属性及下拉菜单 (转)

    http://blog.sina.com.cn/s/blog_6f14b7010101b91b.html https://msdn.microsoft.com/zh-cn/library/ms1718 ...

  9. 整理一些好用的css, javascript资源网站等

    CSS: CSS3信息:http://www.css3.info/ css3生成器:http://css3generator.com/ css3 cross brower生成器:http://css3 ...

  10. Maven 常见错误

    1.ReasonPhrase: Forbidden: |--- 1.注意用户的权限以及角色role的设置,一般是没有权限才会被禁止的. 2.Failed to collect dependencies ...