-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path020.cs
66 lines (52 loc) · 1.47 KB
/
020.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Desafio 020
Problema: O mesmo professor do desafio anterior quer sortear a ordem de
apresentação de trabalhos dos alunos. Faça um programa que leia o
nome dos quatro alunos e mostre a ordem sorteada
Resolução do problema:
*/
using System;
using System.Collections.Generic;
class io {
public static string input(string text) {
Console.Write(text);
return Console.ReadLine();
}
public static void print(object data, string end="\n") {
string text = data.ToString();
Console.Write($"{text}{end}");
}
}
class random {
public static List<string> shuffle(String[] array){
Random random = new Random();
var list = new List<string>(array);
int size = list.Count;
for (int i = size; i > 0; i--){
int randindex = random.Next(size-1);
var aux = list[randindex];
list.Add(aux);
list.RemoveAt(randindex);
}
return list;
}
}
class Program {
public static void Main() {
string nome1 = io.input("1º aluno(a): ");
string nome2 = io.input("2º aluno(a): ");
string nome3 = io.input("3º aluno(a): ");
string nome4 = io.input("4º aluno(a): ");
string[] alunos = {
nome1,
nome2,
nome3,
nome4
};
List<string> alunosAleatorio = random.shuffle(alunos);
io.print(string.Join(
System.Environment.NewLine,
alunosAleatorio
));
}
}