Created
April 18, 2018 05:29
-
-
Save brunoarmanelli/407d473e8bb8a6b0a4d318ead62b7978 to your computer and use it in GitHub Desktop.
Solução do CLSLDR - Class Leader (SPOJ)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| /* | |
| Bruno Henrique Armanelli | |
| Problema Class Leader | |
| Lab de Computacao II - 2018 | |
| */ | |
| public class No { | |
| public int id; | |
| public No Proximo = null; | |
| } | |
| public class ListaCircular { | |
| private No No; | |
| public ListaCircular() { | |
| this.No = null; | |
| } | |
| public void add(int valor) { | |
| No node = new No(); | |
| node.id = valor; | |
| if(this.No == null) { | |
| node.Proximo = node; | |
| this.No = node; | |
| } else { | |
| node.Proximo = this.No.Proximo; | |
| this.No.Proximo = node; | |
| } | |
| } | |
| public void remover(int valor) { | |
| while(No.Proximo.id != valor) { | |
| No = No.Proximo; | |
| } | |
| No.Proximo = No.Proximo.Proximo; | |
| } | |
| public int executaMaratona(int m, int o) { | |
| while(No.id != m) { | |
| No = No.Proximo; | |
| } | |
| while(No != No.Proximo) { | |
| for(int i = 0; i < (o - 1); i++) { | |
| No = No.Proximo; | |
| } | |
| No.Proximo = No.Proximo.Proximo; // Não utilizado remover | |
| } | |
| return No.id; | |
| } | |
| } | |
| public class Test { | |
| public static int resolve(int n, int m, int o) { | |
| ListaCircular Alunos = new ListaCircular(); | |
| for(int i = n; i > 0; i--) { | |
| Alunos.add(i); | |
| } | |
| int resultado = Alunos.executaMaratona(m, o); | |
| return resultado; | |
| } | |
| public static void Main() { | |
| int resultado, repeticoes, n, m, o; | |
| repeticoes = int.Parse(Console.ReadLine()); | |
| while (repeticoes > 0) { | |
| // Lê e faz split por espaços | |
| String linha = Console.ReadLine(); | |
| string[] dados = linha.Split(' '); | |
| n = int.Parse(dados[0]); | |
| m = int.Parse(dados[1]); | |
| o = int.Parse(dados[2]); | |
| // Executa e imprime | |
| resultado = resolve(n, m, o); | |
| Console.WriteLine(resultado); | |
| repeticoes--; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment