Last active
December 14, 2017 14:47
-
-
Save MrZoidberg/d213724fa9a49c613e9b to your computer and use it in GitHub Desktop.
Задачка Бобука
This file contains 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
///Из заданного списка вывести поочередно, рандомно, а главное, без повторений, все его элементы. | |
public struct Banner | |
{ | |
public int id; | |
public string url; | |
} | |
class Program | |
{ | |
private static List<Banner> _banners; | |
static void Main(string[] args) | |
{ | |
int n = 10000000; | |
int k = 9999999; | |
int counter = 0; | |
try | |
{ | |
_banners = new List<Banner>(); | |
Random rnd = new Random(); | |
for (int i = 0; i < n; i++) | |
{ | |
int r = rnd.Next(); | |
_banners.Add(new Banner() { id = i, url = r.ToString() }); | |
} | |
Console.WriteLine("Filled"); | |
do | |
{ | |
for (int i = k - 1; i >= 1; i--) | |
{ | |
int j = rnd.Next(0, i + 1); | |
Banner tmp = _banners[j]; | |
_banners[j] = _banners[i]; | |
_banners[i] = tmp; | |
} | |
/* | |
string result = String.Empty; | |
for (int i = 0; i < k; i++) | |
{ | |
result += _banners[i].id + " "; | |
} | |
*/ | |
Console.WriteLine(counter); | |
counter++; | |
} while (true); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
Console.WriteLine("Done"); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment