Rezultati

Up. imeNalogaJezikRezultatČas oddaje
functor2018 Prehitevanje C++ 100/100OK 04. okt '18 @ 17:06

Test Točke Porabljen spomin Porabljen čas Status
#1 16/16 3,164 MiB 0,000 s OK
#2 16/16 3,168 MiB 0,004 s OK
#3 17/17 3,254 MiB 0,004 s OK
#4 17/17 4,539 MiB 0,549 s OK
#5 17/17 30,633 MiB 0,000 s OK
#6 17/17 3,188 MiB 0,000 s OK

Ocenjevani program (prehitevanje.cpp):
#include <cstdio>
#include <iostream>
#include <string>
#include <map>

using namespace std;

struct Kolesar
{
	string name;
	struct Kolesar* next = NULL, *prev = NULL;
} *root = NULL;

int main()
{
	map<string, struct Kolesar*> kolesarji;
	
	int n;
	int p;
	scanf("%d", &n);
	
	Kolesar* prev = new Kolesar();
	root = prev;
	cin >> prev->name;
	kolesarji.insert(pair<string, Kolesar*>(prev->name, prev));
	
	for (int i = 1; i < n; i++)
	{
		struct Kolesar* k = new Kolesar();
		cin >> k->name;
		kolesarji.insert(pair<string, Kolesar*>(k->name, k));
		k->prev = prev;
		prev->next = k;
		prev = k;
	}

	scanf("%d", &p);

	for (int i = 0; i < p; i++)
	{
		string from, to;
		cin >> from >> to;
		Kolesar *a = kolesarji.find(from)->second,
		        *b = kolesarji.find(to)->second;

		if (a->prev != NULL)
			a->prev->next = a->next;
		else
			root = a->next;

		if (a->next != NULL)
			a->next->prev = a->prev;

		a->prev = b->prev;
		a->next = b;
		if (b->prev != NULL)
		{
			b->prev->next = a;
		}
		else
		{
			root = a;
		}
		b->prev = a;
	}

	while (root != NULL)
	{
		cout << root->name << endl;
		root = root->next;
	}
}