迷宫

匿名 (未验证) 提交于 2019-12-02 23:32:01
 http://codeforces.com/problemset/problem/6/B import java.util.*; public class CF6B { 	public static void main(String[] args) { 		Scanner in = new Scanner(System.in); 		int n = in.nextInt(); 		int m = in.nextInt(); 		char p = in.next().charAt(0); 		HashSet<Character> ans = new HashSet<Character>(); 		int[] di = {0,0,1,-1}; 		int[] dj = {1,-1,0,0}; 		char[][] map = new char[n][m]; 		for(int i = 0; i < n; i ++) 			map[i] = in.next().toCharArray(); 		for(int i = 0; i < n; i ++) 		{ 			for(int j = 0; j < m; j ++) 			{ 				if(map[i][j]!=p) 					continue; 				for(int k = 0; k < 4; k ++) 				{ 					int ni = i + di[k]; 					int nj = j + dj[k]; 					if(ni>-1&&ni<n&&nj>-1&&nj<m&&map[ni][nj]!=p&&map[ni][nj]!='.') 						ans.add(map[ni][nj]); 				} 			} 		} 		System.out.println(ans.size()); 	} }

文章来源: https://blog.csdn.net/qq_39370495/article/details/89785809
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!