private static void IndexarAutor(ref ConjuntoTeste conjuntoTeste, string autor) { if (!conjuntoTeste.IndiceAutores.Keys.Contains(autor)) { conjuntoTeste.IndiceAutores.Add(autor, conjuntoTeste.IndiceAutores.Count); } }
private static void AdicionarArestasAutores(ref ConjuntoTeste conjuntoTeste, string[] autoresArtigo) { IndexarAutor(ref conjuntoTeste, autoresArtigo[0]); for (int i = 0; i < autoresArtigo.Length - 1; i++) { for (int j = i + 1; j < autoresArtigo.Length; j++) { IndexarAutor(ref conjuntoTeste, autoresArtigo[j]); conjuntoTeste.Grafo.AdicionarAresta( conjuntoTeste.IndiceAutores[autoresArtigo[i]], conjuntoTeste.IndiceAutores[autoresArtigo[j]]); } } }
private static string ProcessarNumeroErdos(List <string> linhas) { var resposta = new StringBuilder(); var indiceTeste = 0; var numeroTeste = 0; while (linhas[indiceTeste] != "0") { numeroTeste++; var conjuntoTeste = new ConjuntoTeste { Numero = numeroTeste, Grafo = new GrafoListaAdjacencia(QUANTIDADE_MAXIMA_ARTIGOS), IndiceAutores = new Dictionary <string, int>(), QuantidadeArtigos = int.Parse(linhas[indiceTeste]) }; var indiceInicial = indiceTeste + 1; var indiceFinal = (indiceInicial + conjuntoTeste.QuantidadeArtigos) - 1; for (int i = indiceInicial; i <= indiceFinal; i++) { var linhaTratada = TratarLinhaAutores(linhas[i]); var autoresArtigo = linhaTratada.Split(','); AdicionarArestasAutores(ref conjuntoTeste, autoresArtigo); } indiceTeste = indiceFinal + 1; AdicionarConjuntoTestes(ref resposta, conjuntoTeste); } return(resposta.ToString().Trim()); }
private static void AdicionarConjuntoTestes(ref StringBuilder resposta, ConjuntoTeste conjuntoTeste) { resposta.AppendLine($"Teste {conjuntoTeste.Numero}"); List <string> autores = null; try { var inicial = conjuntoTeste.IndiceAutores[NOME_ERDOS]; var buscaLargura = new BuscaLargura(conjuntoTeste.Grafo, inicial); autores = conjuntoTeste.IndiceAutores.Keys.ToList(); autores.Remove(NOME_ERDOS); OrdernarAutores(ref autores); foreach (var autor in autores) { string numeroErdos = RetornarNumeroErdos(buscaLargura, conjuntoTeste.IndiceAutores[autor]); resposta.AppendLine($"{autor}: {numeroErdos}"); } } catch (KeyNotFoundException) { autores = conjuntoTeste.IndiceAutores.Keys.ToList(); OrdernarAutores(ref autores); foreach (var autor in autores) { resposta.AppendLine($"{autor}: {ERDOS_INFINITO}"); } } finally { resposta.AppendLine(); } }