Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. public static void Rennazin()
  2.         {
  3.             var listaDeParticipantes = new List<dynamic>
  4.             {
  5.                 new
  6.                 {
  7.                     Nome = "Turma da Cerveja",
  8.                     Pontuacao = 8000.0
  9.                 },
  10.                 new
  11.                 {
  12.                     Nome = "Turma da LG",
  13.                     Pontuacao = 10000.0
  14.                 },
  15.                 new
  16.                 {
  17.                     Nome = "Turma da Caaa",
  18.                     Pontuacao = 4000.0
  19.                 },
  20.                 new
  21.                 {
  22.                     Nome = "Turma da LGddsds",
  23.                     Pontuacao = 89500.0
  24.                 },
  25.                 new
  26.                 {
  27.                     Nome = "Turma da Cerveja",
  28.                     Pontuacao = 4000.0
  29.                 },
  30.                 new
  31.                 {
  32.                     Nome = "Turma da LG",
  33.                     Pontuacao = 20000.0
  34.                 },
  35.                 new
  36.                 {
  37.                     Nome = "Turma da Caaa",
  38.                     Pontuacao = 6000.0
  39.                 },
  40.                 new
  41.                 {
  42.                     Nome = "Turma da LGddsds",
  43.                     Pontuacao = 89000.0
  44.                 }
  45.  
  46.             };
  47.  
  48.             listaDeParticipantes = listaDeParticipantes.OrderBy(x => x.Nome).ToList();
  49.  
  50.             while (listaDeParticipantes.Count > 2)
  51.             {
  52.                 listaDeParticipantes = Processo(listaDeParticipantes);
  53.             }
  54.  
  55.             var vencedores = listaDeParticipantes.OrderByDescending(x => x.Pontuacao).ToList();
  56.         }
  57.  
  58.         private static List<dynamic> Processo(List<dynamic> listaDeParticipantes)
  59.         {
  60.             var listaDeVencedores = new List<dynamic>();
  61.             var quantidadeDeTimes = listaDeParticipantes.Count;
  62.             for (int i = 0; i < quantidadeDeTimes / 2; i++)
  63.             {
  64.                 listaDeVencedores.Add(ObtenhaVencedor(listaDeParticipantes[i], listaDeParticipantes[quantidadeDeTimes - i - 1]));
  65.             }
  66.  
  67.             return listaDeVencedores;
  68.         }
  69.  
  70.         public static dynamic ObtenhaVencedor(dynamic a, dynamic b)
  71.         {
  72.             return a.Pontuacao < b.Pontuacao ? b : a;
  73.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement