public class Program
{
public static void Main()
{
List<string> listStr = new List<string>();
listStr.Add("***a ");
listStr.Add(" e* ");
listStr.Add(" ***d** ");
listStr.Add(" e**** ");
listStr.Add(" hgj*** ");
string[,] grid = new string[35,35];
for (int i = 0; i < listStr.Count; i++){
for(int j = 0; j < listStr[i].Length; j++){
grid[i,j] = listStr[i][j].ToString();
}
}
Console.WriteLine(grid[0,0]);
Console.WriteLine(grid[0,3]);
Console.WriteLine(grid[1,3]);
Dictionary<string, string> dict = new Dictionary<string, string>();
for(int k = 0; k<35;k++){
for (int m = 0; m<35; m++){
//Console.WriteLine(grid[k,m]) ;
var sub_dict = SearchPath (k, m, grid);
foreach(var item in sub_dict){
if(!dict.ContainsKey(item.Key) ){
dict.Add(item.Key, item.Value);
}
}
}
}
string strReturn = "";
foreach(var dic in dict){
if(dic.Value != "*" && dic.Value != null){
//Console.Write(dic.Value);
strReturn = strReturn + dic.Value;
}
}
Console.WriteLine(strReturn. Replace(" ",""));
}
public static Dictionary<string,string> SearchPath (int x, int y, string[,] grid){
Dictionary<string,string> toRetrun = new Dictionary<string,string>();
if(grid[x,y] != null){
toRetrun.Add(String.Format("{ 0}{1}",(x).ToString(),y. ToString()), grid[x,y].ToString());
if(x - 1 >= 0 && x -1 < 35){
if(grid[x-1,y] != null && grid[x-1,y] != ""){
toRetrun.Add(String.Format("{ 0}{1}",(x-1).ToString(),y. ToString()), grid[x-1,y].ToString());
}
}
if(x + 1 >= 0 && x+1 < 35){
if(grid[x+1,y] != null && grid[x+1,y] != ""){
toRetrun.Add(String.Format("{ 0}{1}",(x+1).ToString(),y. ToString()), grid[x+1,y].ToString());
}
}
if(y - 1 >= 0 && y -1 < 35){
if(grid[x,y - 1] != null && grid[x,y - 1] !=""){
toRetrun.Add(String.Format("{ 0}{1}",x.ToString(),(y - 1).ToString()), grid[x,y - 1].ToString());
}
}
if(y + 1 >= 0 && y+1 < 35){
if(grid[x,y + 1] != null && grid[x,y + 1] != ""){
toRetrun.Add(String.Format("{ 0}{1}",x.ToString(),(y+1). ToString()), grid[x,y+1].ToString());
}
}
}
return toRetrun;
}
}
Aucun commentaire:
Enregistrer un commentaire