156 lines
4.2 KiB
C#
156 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Program
|
|
{
|
|
//B csoport lottó
|
|
|
|
static void Feladat1()
|
|
{
|
|
//1. feladat
|
|
int[] szamok = { };
|
|
|
|
Console.WriteLine("Add meg az 52.hét lottó számait!");
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
Console.WriteLine($"Add meg az {i+1}. számot!");
|
|
int het52 = Convert.ToInt32(Console.ReadLine());
|
|
szamok = szamok.Append(het52).ToArray();
|
|
}
|
|
Console.WriteLine();
|
|
|
|
//2. feladat
|
|
Array.Sort(szamok);
|
|
foreach (int n in szamok)
|
|
{
|
|
Console.WriteLine(n);
|
|
}
|
|
Console.WriteLine();
|
|
|
|
//3. feladat
|
|
Console.WriteLine("Addj meg egy számot 1-51 között!");
|
|
int felhszam = Convert.ToInt32(Console.ReadLine());
|
|
|
|
//4. feladat
|
|
int paratlandb = 0;
|
|
int[,] lottoszamok = new int[51,5];
|
|
FileStream fs = new FileStream(@"C:\Users\szabomarton\Desktop\C#\20230913_doga\lottosz.txt", FileMode.Open);
|
|
StreamReader sr = new StreamReader(fs);
|
|
|
|
FileStream fs_2 = new FileStream(@"C:\Users\szabomarton\Desktop\C#\20230913_doga\lotto52ki.txt", FileMode.CreateNew);
|
|
StreamWriter sw = new StreamWriter(fs_2);
|
|
|
|
for (int i = 0; i < 51; ++i)
|
|
{
|
|
string str = sr.ReadLine();
|
|
string[] hetiszamok = str.Split(' ');
|
|
|
|
for (int j = 0; j < hetiszamok.Length; ++j)
|
|
{
|
|
int szam = Convert.ToInt32(hetiszamok[j]);
|
|
lottoszamok[i,j] = szam;
|
|
if (szam % 2 != 0)
|
|
{
|
|
paratlandb++;
|
|
}
|
|
sw.Write($"{szam} ");
|
|
|
|
}
|
|
sw.WriteLine();
|
|
|
|
}
|
|
|
|
Console.WriteLine("A megadott heti lottószámok:");
|
|
for (int g = 0; g < lottoszamok.GetLength(1); ++g)
|
|
{
|
|
Console.WriteLine(lottoszamok[felhszam - 1, g]);
|
|
}
|
|
|
|
|
|
sr.Close();
|
|
fs.Close();
|
|
|
|
|
|
//5. feladat
|
|
bool van = false;
|
|
int[] kihuzottak = { };
|
|
|
|
for (int i = 0; i < lottoszamok.GetLength(0); ++i)
|
|
{
|
|
for (int j = 0; j < lottoszamok.GetLength(1); ++j)
|
|
{
|
|
int szam_1 = lottoszamok[i, j];
|
|
bool nincsbenne = !kihuzottak.Contains(szam_1);
|
|
if (nincsbenne)
|
|
{
|
|
kihuzottak = kihuzottak.Append(szam_1).ToArray();
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int g = 1; g < 91; ++g)
|
|
{
|
|
if (!kihuzottak.Contains(g))
|
|
{
|
|
van = true;
|
|
}
|
|
}
|
|
|
|
if (van)
|
|
{
|
|
Console.WriteLine("Van");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Nincs");
|
|
}
|
|
|
|
//6.feladat
|
|
Console.WriteLine($"A páratlanok száma: {paratlandb}");
|
|
|
|
|
|
//7. feladat
|
|
|
|
|
|
sw.WriteLine(szamok.ToString());
|
|
sw.Close();
|
|
fs_2.Close();
|
|
|
|
//8. feladat
|
|
|
|
//9.feladat
|
|
int[] primek = { };
|
|
for (int i = 2; i <91; ++i)
|
|
{
|
|
if (!primek.Contains(i))
|
|
{
|
|
primek = primek.Append(i).ToArray();
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("A prímszámok amiket nem tartalmaz: ");
|
|
for (int g = 1; g < 91; ++g)
|
|
{
|
|
if (!primek.Contains(g))
|
|
{
|
|
Console.WriteLine(g);
|
|
}
|
|
}
|
|
|
|
}
|
|
static void Main(string[] args)
|
|
{
|
|
Feladat1();
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
}
|
|
|
|
|