Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 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 lotto
  8. {
  9.     class Program
  10.     {
  11.         static Random rnd = new Random();
  12.         static void Main(string[] args)
  13.         {
  14.             // szamok[2] = 9; 2. indexű elem felülíródik 9-re
  15.             // szamok.Instert(2,20); új elem létrejön 2. helyre a 2. és utána lévők 1-el nőnek.
  16.             // szamok.RemoveAt(2); kitörli a 2. elemet
  17.             int db = 5;
  18.             int min = 1;
  19.             int max = 90;
  20.             int index;
  21.             int veletlen;
  22.             bool letezik;
  23.             int tipp;
  24.  
  25.             List<int> lottoSzamok = new List<int>();
  26.             List<int> tippek = new List<int>();
  27.             List<int> talalatok = new List<int>();
  28.  
  29.             index = 0;
  30.             while (index < db)
  31.             {
  32.                 letezik = false;
  33.                 veletlen = rnd.Next(min, max + 1);
  34.                 for (int i = 0; i < lottoSzamok.Count; i++)
  35.                 {
  36.                     if (lottoSzamok[i] == veletlen)
  37.                         letezik = true;
  38.                 }
  39.                 if (!letezik)
  40.                 {
  41.                     lottoSzamok.Add(veletlen);
  42.                     index++;
  43.                 }
  44.             }
  45.             index = 0;
  46.             while (index < db)
  47.             {
  48.                 letezik = false;
  49.                 do
  50.                 {
  51.                     Console.Write("{0}. tipp: ", index + 1);
  52.                 } while (!int.TryParse(Console.ReadLine(), out tipp) || tipp < min || tipp > max);
  53.                 veletlen = rnd.Next(min, max + 1);
  54.                 for (int i = 0; i < tippek.Count; i++)
  55.                 {
  56.                     if (tippek[i] == tipp)
  57.                         letezik = true;
  58.                 }
  59.                 if (!letezik)
  60.                 {
  61.                     tippek.Add(tipp);
  62.                     index++;
  63.                 }
  64.             }
  65.             Console.Clear();
  66.             Console.WriteLine("Az eheti lottószámok:");
  67.             for (int i = 0; i < lottoSzamok.Count - 1; i++)
  68.                 Console.Write("{0}, ", lottoSzamok[i]);
  69.             Console.WriteLine(lottoSzamok[lottoSzamok.Count-1]);
  70.  
  71.             Console.WriteLine("Az Ön Tippjei:");
  72.             for (int i = 0; i < tippek.Count - 1; i++)
  73.                 Console.Write("{0}, ", tippek[i]);
  74.             Console.WriteLine(tippek.Last());
  75.  
  76.             for (int i = 0; i < lottoSzamok.Count; i++)
  77.             {
  78.                 for (int j = 0; j < tippek.Count; j++)
  79.                 {
  80.                     if (lottoSzamok[i] == tippek[j])
  81.                         talalatok.Add(lottoSzamok[i]);
  82.                 }
  83.             }
  84.             Console.WriteLine("Önnek {0} találata van: ", talalatok.Count);
  85.             if (talalatok.Count == 0)
  86.                 Console.WriteLine("-");
  87.             else
  88.             {
  89.                 for (int i = 0; i < talalatok.Count - 1; i++)
  90.                     Console.Write("");
  91.             }
  92.             for (int i = 0; i < lottoSzamok.Count - 1; i++)
  93.                 Console.Write("{0}, ", lottoSzamok[i]);
  94.             Console.WriteLine(lottoSzamok[lottoSzamok.Count-1]);
  95.             Console.ReadLine();
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement