fork download
  1. var lines = File.ReadAllLines(@"c:\map.txt");
  2. var m = (from l in lines select l.Replace('S','0').ToCharArray()).ToArray();
  3. int gx = -1, gy = -1, p = -1;
  4. for (int n = 0; ; n++)
  5. {
  6. bool loop = false;
  7. for (int y = 0; y < m.Length; y++)
  8. for (int x = 0; x < m[0].Length; x++)
  9. if (m[y][x] == n + '0')
  10. {
  11. if (m[y][x - 1] == 'G') { loop = false; gx = x - 1; gy = y; p = m[y][x]; break; }
  12. if (m[y][x + 1] == 'G') { loop = false; gx = x + 1; gy = y; p = m[y][x]; break; }
  13. if (m[y - 1][x] == 'G') { loop = false; gx = x; gy = y - 1; p = m[y][x]; break; }
  14. if (m[y + 1][x] == 'G') { loop = false; gx = x; gy = y + 1; p = m[y][x]; break; }
  15. char c = (char)(m[y][x] + 1);
  16. if (m[y][x - 1] == '.' || m[y][x - 1] > c) { loop = true; m[y][x - 1] = c; };
  17. if (m[y][x + 1] == '.' || m[y][x + 1] > c) { loop = true; m[y][x + 1] = c; };
  18. if (m[y - 1][x] == '.' || m[y - 1][x] > c) { loop = true; m[y - 1][x] = c; };
  19. if (m[y + 1][x] == '.' || m[y + 1][x] > c) { loop = true; m[y + 1][x] = c; };
  20. }
  21. if (!loop) break;
  22. }
  23. /*
  24.   for (int y = 0; y < m.Length; y++){
  25.   for (int x = 0; x < m[0].Length; x++)
  26.   Console.Write(m[y][x]);
  27.   Console.Write(Environment.NewLine);
  28.   }
  29.   */
  30. if (p == -1 ) { Console.WriteLine("no route"); return; }
  31. string ret ="";
  32. while (m[gy][gx] != '0')
  33. {
  34. if (m[gy][gx - 1] == p) { gx = gx - 1; ret = 'r' + ret; p--; continue; }
  35. if (m[gy][gx + 1] == p) { gx = gx + 1; ret = 'l' + ret; p--; continue; }
  36. if (m[gy - 1][gx] == p) { gy = gy - 1; ret = 'd' + ret; p--; continue; }
  37. if (m[gy + 1][gx] == p) { gy = gy + 1; ret = 'u' + ret; p--; continue; }
  38. }
  39. Console.WriteLine(ret);
  40. Console.ReadLine();
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(1,17): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(2,17): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(3,17): error CS0116: A namespace can only contain types and namespace declarations
prog.cs(4,15): error CS8025: Parsing error
Compilation failed: 4 error(s), 0 warnings
stdout
Standard output is empty