Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Roboti
- {
- class Program
- {
- void Igra()
- {
- int MAXR = 100, MAXS = 100, MAXPOTEZA = 100;
- int R, S, N;
- string[,] ploca = new string[MAXR, MAXS + 1], pomocna = new string[MAXR, MAXS + 1];
- string[] igrac = new string[MAXPOTEZA + 1];
- R = Convert.ToInt32(Console.ReadLine());
- S = Convert.ToInt32(Console.ReadLine());
- for (int r = 0; r < R; ++r)
- {
- ploca[r, 0] = Console.ReadLine();
- }
- N = igrac.Length;
- int igrac_r = 0, igrac_s = 0;
- for (int r = 0; r < R; ++r)
- {
- for (int s = 0; s < S; ++s)
- {
- if (ploca[r, s] == "I")
- {
- igrac_r = r;
- igrac_s = s;
- }
- }
- }
- for (int i = 0; i < N; ++i)
- {
- for (int r = 0; r < R; ++r)
- for (int s = 0; s < S; ++s)
- pomocna[r, s] = ".";
- igrac_r += 1 - (Convert.ToChar(igrac[i]) - '1') / 3;
- igrac_s += (Convert.ToChar(igrac[i]) - '1') % 3 - 1;
- if (ploca[igrac_r, igrac_s] == "R")
- {
- Console.WriteLine("Kraj {0}\n", i + 1);
- return;
- }
- pomocna[igrac_r, igrac_s] = "I";
- for (int r = 0; r < R; ++r)
- for (int s = 0; s < S; ++s)
- if (ploca[r, s] == "R")
- {
- int dr = sgn(igrac_r - r);
- int ds = sgn(igrac_s - s);
- if (pomocna[r + dr, s + ds] == "I")
- {
- Console.WriteLine("Kraj {0}\n", i + 1);
- return;
- }
- if (pomocna[r + dr, s + ds] == ".") pomocna[r + dr, s + ds] = "R";
- else pomocna[r + dr, s + ds] = "X";
- }
- for (int r = 0; r < R; ++r)
- for (int s = 0; s < S; ++s)
- {
- if (pomocna[r, s] == "X") pomocna[r, s] = ".";
- ploca[r, s] = pomocna[r, s];
- }
- }
- for (int r = 0; r < R; ++r) Console.WriteLine("\n{0}", ploca[r, 0]);
- }
- static void Main(string[] args)
- {
- Program p = new Program();
- p.Igra();
- }
- int sgn(int x)
- {
- if (x < 0) return -1;
- if (x > 0) return 1;
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement