using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Algorithms07 { class Program { static void Main(string[] args) { //ZADANIE 1. //Wygenerować napis losowy złożony z 4 cyfr i 4 liter w dowlnej kolejności. Random rnd = new Random(); int litera=0; char[] napis = new char[8]; do { litera = 0; for (int i = 0; i < 8; i++) { napis[i] = (char)rnd.Next(48, 122); if ((napis[i] > 57 && napis[i] < 65) || (napis[i] > 90 && napis[i] < 97)) { napis[i] = (char)rnd.Next(48, 122); i--; } } for(int j = 0; j < 8; j++) { if ((napis[j] >= 65 && napis[j] <= 90) || (napis[j] >= 97 && napis[j] <= 122)) litera++; } } while(litera!=4); foreach (char i in napis) Console.Write("{0}", i); Console.WriteLine(); //ZADANIE 2. //a) Czy podany napis zawiera podciąg złożony kolejno z 3 liter i 2 cyfr. /* String napisB; napisB = String.Join("", napis); if (Regex.IsMatch(napisB, "[0-9]{2}-[0-9]{3} [A-Z]{1}[a-z]*")) Console.WriteLine("True"); */ //ZADANIE 3. //Dla dowolnego napisu spradzić czy jest on poprawnym adresem 21-500 Biała Podlaska. string adres; Regex regA = new Regex(@"[0-9]{2}-[0-9]{3} [A-Z]{1}[a-z]*"); Regex regB = new Regex(@"[0-9]{2}-[0-9]{3} [A-Z]{1}[a-z]* [A-Z]{1}[a-z]*"); //adres = Console.ReadLine(); adres = "21-500 Biała Podlaska"; if(regA.IsMatch(adres) || regB.IsMatch(adres)) Console.WriteLine("Podany adres jest prawidłowy!"); else Console.WriteLine("Podany adres jest nieprawidłowy!"); Console.ReadLine(); } } }