Esempio n. 1
0
int main(int argc, char const *argv[])
{
	
	string reader,read;
	
	int leitor;

	cin>> reader >> leitor;

	if (reader.compare("*Vertices") == 0)
	{
		Grafo *g = new Grafo(leitor);

		cin>> read;

		while (read.compare("*Arcs") != 0 && read.compare("*Edges") != 0)
		{
			leitor = atoi(read.c_str());

			cin>> reader;

			g->inserirVertice(leitor,reader);

			cin>> read;
		}

		int flag;
		if (read.compare("*Arcs") == 0)
		{
			flag = 0;
			g->setTipo(true);
		}
		else
		{
			if (read.compare("*Edges") == 0)
			{
				flag = 1;
				g->setTipo(false);
			}
			else
			{
				cout<< "Entrada Invalida "<<endl;
				return 1;
			}
		}

		cin>> read;
		while(read.compare("*Queries") != 0)
		{
			int Id1, Id2, peso;

			Id1 = atoi(read.c_str());

			cin>> read;

			Id2 = atoi(read.c_str());

			cin>> read;

			peso = atoi(read.c_str());


			if (flag == 0)
			{
				g->inserirAresta(Id1,Id2,peso);
			}
			else
			{
				g->inserirAresta(Id1,Id2,peso);
				g->inserirAresta(Id2,Id1,peso);
			}
			cin>> read;
		}

		cin>> reader;
		while (reader.compare("@") != 0)
		{
			if (reader.compare("get") == 0)
			{
				cin>> reader;
				int id = atoi(reader.c_str());
				g->getId(id);
			} else {
				if (reader.compare("delete") == 0)
int main(int argc, char const *argv[])
{
	string reader,read;
	
	int leitor;
	SDL_Surface * superficie;

	bool rodando = true;
	bool pronto = false;

	cin>> reader >> leitor;


	if (reader.compare("*Vertices") == 0)
	{
		Grafo *g = new Grafo(leitor);

		cin>> read;

		while (read.compare("*Arcs") != 0 && read.compare("*Edges") != 0)
		{
			leitor = atoi(read.c_str());

			cin>> reader;

			g->inserirVertice(leitor,reader);

			cin>> read;
		}

		bool flag; 
		if (read.compare("*Arcs") == 0)
		{
			g->setDirecionado(false);
			flag = false;
		}
		else
		{
			if (read.compare("*Edges") == 0)
			{
				g->setDirecionado(true);
				flag = true;

			}
			else
			{
				cout<< "Entrada Invalida "<<endl;
				return 1;
			}
		}

		cin>> read;
		while(read.compare("@") != 0)
		{
			int Id1, Id2, peso;

			Id1 = atoi(read.c_str());

			cin>> read;

			Id2 = atoi(read.c_str());

			cin>> read;

			peso = atoi(read.c_str());


			if (flag == false)
			{
				g->inserirAresta(Id1,Id2,peso);
			}
			else
			{
				g->inserirAresta(Id1,Id2,peso);
				g->inserirAresta(Id2,Id1,peso);
			}
			cin>> read;
		}

		g->inserirAresta(0,0,INT_MIN);
		SDL_Init (SDL_INIT_EVERYTHING);
		TTF_Init();
		superficie = SDL_SetVideoMode (LARGURA, ALTURA, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
		bool flag2 = false;
		bool flag3 = false;
		while(rodando) {
			SDL_Event evento;
			SDL_PollEvent(&evento);
			if (!pronto) {
				pronto = !g->calcula();
				desenha (superficie, g,flag2,flag3);
			} else {
				SDL_Delay(1);
			}
			if (evento.type == SDL_QUIT) {
				SDL_FreeSurface(superficie);
				SDL_Quit();
				rodando = 0;
			} else {
				if (evento.type == SDL_KEYDOWN)
				{
					if (evento.key.keysym.sym == SDLK_n)
					{
						SDL_Delay(150);
						flag2 = !flag2;
						pronto = false;
					}
					if (evento.key.keysym.sym == SDLK_p)
					{
						SDL_Delay(150);
						flag3 = !flag3;
						pronto = false;
					}
				}
			}
		}
	}