Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace Kolokwium_algorytmy
- {
- class Program
- {
- public string zadanie1()
- {
- Random random = new Random();
- Regex regex = new Regex(@"^[A-Z]{3}[0-9]$");
- string litery = "ABCDEFGHIJKLMNOPQRSTUWXYZ";
- string cyfry = "1234567890";
- string napis = null;
- int n = random.Next(0, 10);
- int kolejnosc = random.Next(0, 2);
- if (kolejnosc == 0)
- {
- for (int i = 0; i < 3; i++)
- {
- napis += litery[random.Next(0, litery.Length)];
- }
- for (int j = 0; j < n; j++)
- {
- napis += cyfry[random.Next(0, cyfry.Length)];
- }
- return napis;
- Console.WriteLine(" ", regex.IsMatch(napis));
- }
- else
- {
- for(int i = 0; i < n; i++)
- {
- napis += cyfry[random.Next(0, cyfry.Length)];
- }
- for (int j = 0; j < 3; j++)
- {
- napis += litery[random.Next(0, litery.Length)];
- }
- return napis;
- Console.WriteLine(" ", regex.IsMatch(napis));
- }
- return napis;
- }
- static void Main(string[] args)
- {
- Program obiekt = new Program();
- Console.WriteLine(obiekt.zadanie1());
- Stos obiekt2 = new Stos(6);
- Console.Write(obiekt2.zadanie4());
- Console.WriteLine(Regex.IsMatch(obiekt.zadanie2(), (@"^[A-Z]{3}[0-9]$"));
- Console.ReadKey();
- }
- }
- class Stos
- {
- int?[] array;
- int number = 0;
- public Stos(int size)
- {
- array = new int?[size];
- }
- public Stos(Stos s)
- {
- int?[] array2;
- array2 = new int?[s.zwrocTablice.Length * 2];
- for(int i = 0; i < array2.Length; i++)
- {
- array2[i] = array[i];
- }
- }
- public void Add(int number)
- {
- if (number != array.Length)
- {
- array[number++] = number;
- }
- }
- public int? Peek()
- {
- int? back = null;
- if (number != 0)
- {
- back = array[--number];
- }
- return back;
- }
- public int?[] zwrocTablice
- {
- get
- {
- return array;
- }
- }
- public string zadanie4()
- {
- Random random = new Random();
- string napis2 = "abcdefghijklmnopqrstuwxz";
- string zadanie4 = null;
- for(int i = 0; i < 8; i++)
- {
- zadanie4 += napis2[random.Next(0, napis2.Length)];
- }
- return zadanie4;
- }
- }
- class Queue
- {
- int?[] array;
- int head = 0, tail = 0, size = 0;
- public Queue(int size)
- {
- array = new int?[size];
- }
- public void Enque(int number)
- {
- if (size != array.Length)
- {
- size++;
- array[tail++] = number;
- tail = tail % array.Length;
- }
- }
- public int? Deque()
- {
- int? back = null;
- if (size != 0)
- {
- back = array[head];
- array[head++] = null;
- size--;
- head = head % array.Length;
- }
- return back;
- }
- public int dodaj(int n)
- {
- Random random = new Random();
- int wartosc;
- for(int i = 0; i < n; i++)
- {
- wartosc = random.Next(0, 10);
- }
- return n;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement