Rezultati

Up. imeNalogaJezikRezultatČas oddaje
DROPTABLE-2017 Prijateljske besede C# 100/100OK 20. apr '17 @ 17:58

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 19,105 MiB 0,000 s OK
#2 12/12 19,164 MiB 0,000 s OK
#3 12/12 13,648 MiB 0,000 s OK
#4 12/12 21,336 MiB 0,000 s OK
#5 13/13 17,684 MiB 0,000 s OK
#6 13/13 13,629 MiB 0,000 s OK
#7 13/13 13,633 MiB 0,000 s OK
#8 13/13 17,406 MiB 0,000 s OK

Ocenjevani program (PrijateljskeBesede.cs):
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace csharp_template {
  class Program {

    // static string[] FILE_CONTENTS = File.ReadAllLines("tmp");
    // static int FILE_LINE_CNT = 0;

    static string GetLine() {
      return Console.ReadLine();
      // return FILE_CONTENTS[FILE_LINE_CNT++];
    }

    static bool AreCompatible(string str1, string str2) {
      bool fnd = true;
      for (int i = 0; i < 3; i++) {
        if (str1[i] != str2[i]) {
          fnd = false;
          break;
        }
      }
      if (fnd) return true;
      for (int i = 1; i <= 3; i++)
        if (str1[str1.Length - i] != str2[str2.Length - i])
          return false;
      return true;
    }

    class P {
      public string Item;
      public bool IsFriend;
      public bool FriendshipProcessed;
    }

    static P[] entries;
    static void Main(string[] args) {
      int entryCount = int.Parse(GetLine());
      entries = new P[entryCount - 1];
      var first = GetLine();
      for (int i = 0; i < entryCount - 1; i++)
        entries[i] = new P { Item = GetLine() };
      Process(new P { Item = first, IsFriend = true, FriendshipProcessed = true });
      var c = entries.Count(t => t.IsFriend) + 1;
      Console.WriteLine(c);
    }

    static void Process(P entry) {
      entry.FriendshipProcessed = true;
      foreach (var e in entries) {
        if (e == entry || e.IsFriend) continue;
        if (AreCompatible(entry.Item, e.Item)) {
          e.IsFriend = true;
          Process(e);
        }
      }
    }

  }
}