Rezultati

Up. imeNalogaJezikRezultatČas oddaje
4c-2019 Gozdovi C# 100/100OK 24. apr '19 @ 17:50

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 10/10 19,559 MiB 0,000 s OK
#2 [več] 10/10 25,121 MiB 0,000 s OK
#3 [več] 10/10 28,570 MiB 0,000 s OK
#4 [več] 10/10 28,539 MiB 0,000 s OK
#5 [več] 10/10 25,320 MiB 0,000 s OK
#6 [več] 10/10 24,695 MiB 0,000 s OK
#7 [več] 10/10 23,637 MiB 0,000 s OK
#8 [več] 10/10 26,344 MiB 0,000 s OK
#9 [več] 10/10 24,426 MiB 0,000 s OK
#10 [več] 10/10 22,418 MiB 0,000 s OK

Ocenjevani program (Program.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static int n = 0, m = 0;
        static woods[,] fullwoods = new woods[0, 0];
        static void Main(string[] args)
        {
            while (true)
            {
                int woodsCount = 0;
                string s = Console.ReadLine();
                char currenttype;
                List<string> arguments=s.Split(' ').ToList();
                n = Int32.Parse(arguments[0]);
                m = Int32.Parse(arguments[1]);
                if (n == 0 && m == 0) break;
                fullwoods= new woods[n, m];
                for (int i = 0; i < n; i++)
                {
                    List<char> temp=Console.ReadLine().ToCharArray().ToList();
                    for(int j=0;j<m;j++)
                    {
                        fullwoods[i,j] = new woods(temp[j]);
                    }                    
                }
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (!fullwoods[i, j].processed)
                        {
                            process(i, j, fullwoods[i, j].type);
                            woodsCount++;
                        }
                    }
                }
                Console.WriteLine(woodsCount);


            }
        }
        static void process(int x, int y,char type)
        {
            fullwoods[x, y].processed = true;
            if (x >0)
            {
                if (fullwoods[x - 1, y].type == type&& !fullwoods[x - 1, y].processed)
                {
                    process(x - 1, y, type);
                }
            }
            if (x < n - 1)
            {
                if (fullwoods[x + 1, y].type == type && !fullwoods[x + 1, y].processed)
                {
                    process(x + 1, y, type);
                }
            }
            if (y > 0)
            {
                if (fullwoods[x, y-1].type == type && !fullwoods[x, y-1].processed)
                {
                    process(x, y-1, type);
                }
            }
            if (y < m - 1)
            {
                if (fullwoods[x, y+1].type == type&& !fullwoods[x, y+1].processed)
                {
                    process(x, y+1, type);
                }
            }
            if (y < m - 1&& x < n - 1)
            {
                if (fullwoods[x+1, y + 1].type == type && !fullwoods[x+1, y + 1].processed)
                {
                    process(x+1, y + 1, type);
                }
            }
            if (y < m - 1&& x >0)
            {
                if (fullwoods[x-1, y + 1].type == type && !fullwoods[x-1, y + 1].processed)
                {
                    process(x-1, y + 1, type);
                }
            }
            if (y>0 && x < n - 1)
            {
                if (fullwoods[x + 1, y - 1].type == type && !fullwoods[x + 1, y - 1].processed)
                {
                    process(x + 1, y - 1, type);
                }
            }
            if (y > 0 && x>0)
            {
                if (fullwoods[x - 1, y - 1].type == type && !fullwoods[x - 1, y - 1].processed)
                {
                    process(x - 1, y - 1, type);
                }
            }

        }
    }

    class woods
    {
        public char type ;
        public bool processed;
        public woods(char t)
        {
            type = t;
            processed = false;
        }
    }
}