Advertisement
jurek224466

kolokwium 17.01.2018

Jan 17th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 KB | None | 0 0
  1.  public string generuj() {
  2.             StringBuilder napis = new StringBuilder();
  3.             Random r = new Random();
  4.             string pattern = @"[a-z]{5}[0-9]{5}|[0-9]{5}[a-z]{5}";
  5.             Regex reg = new Regex(pattern);
  6.  
  7.             string alfabet = "abcdefghijklmnouprstuwxyz";
  8.  
  9.             for (int i = 0; i < 10; i++) {
  10.                 if (i < 5 ) {
  11.                     napis.Append(alfabet[r.Next(1, alfabet.Length)]);
  12.                 }
  13.                 else {
  14.                     napis.Append(r.Next(1,9));
  15.                 }
  16.  
  17.  
  18.                 return napis.ToString();
  19.  
  20.                 if (reg.IsMatch(napis.ToString())) {
  21.                     Console.WriteLine("Pasuje");
  22.                 }
  23.                 else {
  24.                     Console.WriteLine("Niepasuje");
  25.                 }
  26.  
  27.  
  28.  
  29.  
  30.             }
  31.             return napis.ToString();
  32.         }
  33.  
  34.  
  35.  
  36.         public void zadanie_4() {
  37.             StringBuilder napis = new StringBuilder();
  38.             Random r = new Random();
  39.             Queue<string> kolejka = new Queue<string>();
  40.             Stack<string> stos = new Stack<string>();
  41.             Queue<string> drugakolejka = new Queue<string>();
  42.             string[] napisy = new string[10];
  43.             string alfabet = "abcdefghijklmnouprstuwxyz";
  44.             Regex rw = new Regex("[a,e,i,o,u]+");
  45.             for (int i = 0; i < 10; i++) {
  46.                 for(int j = 0; j < 10; j++) {
  47.                
  48.                 }
  49.                 if (rw.IsMatch(napis.ToString())) {
  50.                     stos.Push(napis.ToString());
  51.                    
  52.                 }
  53.                 else {
  54.                     kolejka.Enqueue(napis.ToString());
  55.                 }
  56.             }
  57.         }
  58.     }
  59. class kolejka
  60.     {
  61.         int[] tablica;
  62.        
  63.         int ogon = 0, głowa = 0, wielkosc = 0;
  64.         public void dodaj(int liczba)
  65.         {
  66.             if (wielkosc< tablica.Length)
  67.             {
  68.                 wielkosc++;
  69.                 tablica[ogon++] = liczba;
  70.                 ogon = ogon % tablica.Length;
  71.             }
  72.  
  73.         }
  74.  
  75.        
  76.         public void usun()
  77.         {
  78.             int licz =0;
  79.             if (wielkosc != 0)
  80.             {
  81.                 licz = tablica[głowa];
  82.                 tablica[głowa]=0;
  83.                 wielkosc--;
  84.                 głowa = głowa + 1 % tablica.Length;
  85.             }
  86.         }
  87.         public void dodajnowe(int n) {
  88.             int ogon2 = 0;
  89.             int i = 0;
  90.             int?[] wartosci = new int?[2 * n];
  91.  
  92.             if (wielkosc < tablica.Length) {
  93.                 wielkosc++;
  94.                 wartosci[ogon++] = tablica[i];
  95.                 ogon2 = ogon2 % wartosci.Length;
  96.             }
  97.  
  98.  
  99.         }
  100.         public kolejka(int wielkosc) {
  101.             dodajnowe(2 *wielkosc);
  102.         }
  103.  
  104.     }
  105. class stos {
  106.  
  107.         int[] numbers;
  108.         private int liczba;
  109.         private int licznik = 0;
  110.         public stos(int liczba) {
  111.             this.liczba = liczba;
  112.         }
  113.         public void dodaj(int liczba) {
  114.             if (liczba != numbers.Length) {
  115.                 numbers[licznik++] = liczba;
  116.             }
  117.         }
  118.  
  119.         public int? usun() {
  120.             int? wartosc = null;
  121.             if (licznik != 0) {
  122.                 wartosc = numbers[--licznik];
  123.             }
  124.             return wartosc;
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement