Rezultati

Up. imeNalogaJezikRezultatČas oddaje
jam-2018 Puzzle C++ 100/100OK 19. apr '18 @ 19:42

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 3,238 MiB 0,004 s OK
#2 10/10 3,035 MiB 0,004 s OK
#3 10/10 3,035 MiB 0,000 s OK
#4 10/10 3,238 MiB 0,004 s OK
#5 10/10 3,238 MiB 0,000 s OK
#6 10/10 3,031 MiB 0,004 s OK
#7 10/10 3,238 MiB 0,000 s OK
#8 10/10 3,238 MiB 0,004 s OK
#9 10/10 3,035 MiB 0,000 s OK
#10 10/10 3,031 MiB 0,004 s OK

Ocenjevani program (main.cpp):
#include <iostream>
#include <vector>
#include <list>
#include <utility>
#include <set>
#include <algorithm>
#include <string>

using namespace std;

class Koscek;
vector<Koscek *> koscki;
int x[] = {1, 2, 1, 2, 3, 3, 1, 2, 3};
int y[] = {1, 1, 2, 2, 1, 2, 3, 3, 3};
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
Koscek ***tab;

class Koscek {
public:
  char stranice[4];
  bool gor;

  explicit Koscek(string);

  void obrni();

  bool vstavi(int);

  void i1();
  void i2();
  void i3();
};

void Koscek::i1() {
  cout << " " << stranice[0] << " ";
}

void Koscek::i2() {
  cout << stranice[3] << " " << stranice[1];
}

void Koscek::i3() {
  cout << " " << stranice[2] << " ";
}

void Koscek::obrni() {
  int temp = stranice[0];
  stranice[0] = stranice[1];
  stranice[1] = stranice[2];
  stranice[2] = stranice[3];
  stranice[3] = temp;
}

bool pase(char a, char b) {
  return abs(a - b) == 'a' - 'A';
}

bool Koscek::vstavi(int i) {
  for (int j = 0; j < 4; j++) {
    int xx = x[i] + dx[j];
    int yy = y[i] + dy[j];

    if (!tab[xx][yy])
      continue;

    if (!pase(tab[x[i]][y[i]]->stranice[j], tab[xx][yy]->stranice[(j + 2) % 4]))
      return false;
  }
  return true;
}

Koscek::Koscek(string s) {
  for (int i = 0; i < 4; i++)
    stranice[i] = s[i];
}

void rek(int i) {
  if (i == 9) {
    for (int y = 1; y < 4; y++) {
      for (int x = 1; x < 4; x++) {
        tab[x][y]->i1();
      }
      cout << endl;
      for (int x = 1; x < 4; x++) {
        tab[x][y]->i2();
      }
      cout << endl;
      for (int x = 1; x < 4; x++) {
        tab[x][y]->i3();
      }
      cout << endl;
    }

    exit(0);
  }

  for (Koscek *koscek : koscki) {
    if (koscek->gor) continue;
    koscek->gor = true;
    tab[x[i]][y[i]] = koscek;

    for (int krog = 0; krog < 4; krog++) {
      koscek->obrni();

      if (koscek->vstavi(i))
        rek(i + 1);
    }

    koscek->gor = false;
    tab[x[i]][y[i]] = nullptr;
  }
}

int main() {
  for (int i = 0; i < 9; i++) {
    string vrstica;
    cin >> vrstica;
    koscki.push_back(new Koscek(vrstica));
  }

  tab = new Koscek **[5];
  for (int i = 0; i < 5; i++)
    tab[i] = new Koscek *[5];

  for (int y = 0; y < 5; y++)
    for (int x = 0; x < 5; x++)
      tab[x][y] = nullptr;

  rek(0);
}