Advertisement
Guest User

TotolotekX

a guest
Jan 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TestNotSoX
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Random genLL = new Random();
  14.             int n;
  15.             int ileLos;
  16.             int[] tabLosowe;
  17.  
  18.             Console.WriteLine("***SuperSoft Company   3018 * **");
  19.             Console.WriteLine("===========================================");
  20.             Console.WriteLine("TOTOLOTEK");
  21.             Console.WriteLine("===========================================");
  22.  
  23.             ileLos = 6;                                //totolotek podstawowy: 6 x <1,49>
  24.             int ileLosPlus = 10;                       //z plusem: 10 x <1,100>
  25.             int ileLosEuro = 5;                        //euro jacket 5 x <1,50>
  26.             tabLosowe = new int[ileLos];
  27.             int[] tabLosowePlus = new int[ileLosPlus];
  28.             int[] tabLosoweEuro = new int[ileLosEuro];
  29.             //losowanie
  30.             Console.WriteLine("MULTILOTEK: Wylosowane liczby to:");
  31.             tabLosowe[0] = genLL.Next(1, 50);
  32.             int[] tabN = new int[ileLos];
  33.             /* for (int i = 0; i < ileLos - 1; i++)
  34.              {
  35.                  tabN[i] = genLL.Next(1, 50);
  36.                  foreach (var e in tabLosowe)
  37.                      if (!(e == tabN[i])) tabLosowe[i] = tabN[i];
  38.                  Console.WriteLine(tabLosowe[i]);
  39.              }*/
  40.             // bardziej elegancki
  41.             /* for (int i = 0; i < ileLos; i++)
  42.              {
  43.                  int losowa;
  44.                  bool unikalna;
  45.                  do                                        //wartość dla "i"-tego miejsca
  46.                  {
  47.                      losowa = genLL.Next(1, 50);
  48.                      unikalna = true;
  49.                      for (int j = 0; j < i; j++)
  50.                          if (losowa == tabLosowe[j])
  51.                              unikalna = false;
  52.                  }
  53.                  while (unikalna == false);
  54.                  tabLosowe[i] = losowa;
  55.              }
  56.              Console.WriteLine("Się wylosowało...");
  57.              foreach (int e in tabLosowe)
  58.                  Console.Write("{0}, ", e);
  59.              Console.WriteLine("Koniec serii");
  60.              */
  61.             //wersja II -mniej elegancka
  62.             LiczLosowe(genLL, ileLos, tabLosowe, 1, 49);
  63.             Console.WriteLine("Się wylosowało II...");
  64.             foreach (int e in tabLosowe)
  65.                 Console.Write("{0}, ", e);
  66.             Console.WriteLine("Koniec serii");
  67.             //teraz Plus
  68.             LiczLosowe(genLL, ileLosPlus, tabLosowePlus, 1, 100);
  69.             LiczLosowe(genLL, ileLosEuro, tabLosoweEuro, 1, 50);
  70.             Console.WriteLine("Się wylosowało Plus...");
  71.             foreach (int e in tabLosowePlus)
  72.                 Console.Write("{0}, ", e);
  73.             Console.WriteLine("Koniec serii");
  74.             Console.WriteLine("Się wylosowało Euro...");
  75.             foreach (int e in tabLosoweEuro)
  76.                 Console.Write("{0}, ", e);
  77.             Console.WriteLine("Koniec serii");
  78.             Console.Write("aby zakończyć - wciśnij dowolny klawisz...");
  79.             Console.ReadKey();
  80.         }
  81.  
  82.         private static void LiczLosowe(Random genLL, int ileLos, int[] tabLosowe, int losowaMin, int losowaMax)
  83.         {
  84.             for (int i = 0; i < ileLos; i++)
  85.             {
  86.                 tabLosowe[i] = genLL.Next(losowaMin, losowaMax+1);
  87.                 for (int j = 0; j < i; j++)
  88.                     if (tabLosowe[i] == tabLosowe[j])
  89.                         i--;
  90.             }
  91.         }
  92.  
  93.         static void Statystyka(int [] tabDane, ref int max, ref double srednia, ref int min)
  94.         {
  95.             min = max = tabDane[0];
  96.             foreach (int e in tabDane)
  97.             {
  98.                 if (e < min) min = e;
  99.                 if (e > max) max = e;
  100.             }
  101.             srednia = (max + min) / 2;
  102.         }
  103.         static void WyznaczMinPP(int[] tabDane, ref int min  )
  104.         {
  105.             min = tabDane[0];
  106.             foreach (int e in tabDane)
  107.                 if (e < min) min = e;
  108.         }
  109.         static void WyznaczMaxPP(int[] tabDane, ref int max)
  110.         {
  111.             max = tabDane[0];
  112.             foreach (int e in tabDane)
  113.                 if (e > max) max = e;
  114.         }
  115.         static int WyznaczMin(int[] tabDane)
  116.         {
  117.             int min = tabDane[0];
  118.             foreach (int e in tabDane)
  119.                 if (e < min) min = e;
  120.             return min;
  121.         }
  122.         static int WyznaczMax(int[] tabDane)
  123.         {
  124.             int max = tabDane[0];
  125.             foreach (var e in tabDane)
  126.                 if (e > max) max = e;
  127.             return max;
  128.         }
  129.         static double LiczSrednia(int[] tabDanych)
  130.         {
  131.             int suma = 0;
  132.             foreach (var e in tabDanych)
  133.                 suma += e;
  134.             return suma / tabDanych.Length;
  135.         }
  136.         static int ZliczX(int[] tabLiczb, int x)
  137.         {
  138.             int ileX = 0;
  139.             foreach (var e in tabLiczb)
  140.                 if (e == x) ileX++;
  141.             return ileX;
  142.         }
  143.  
  144.     }        
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement