Advertisement
miknik97

czekaj

Nov 26th, 2018
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Algorithms07
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             //ZADANIE 1.
  15.             //Wygenerować napis losowy  złożony z 4 cyfr i 4 liter w dowlnej kolejności.
  16.  
  17.             Random rnd = new Random();
  18.             int litera=0;
  19.             char[] napis = new char[8];
  20.             do
  21.             {
  22.                 litera = 0;
  23.                 for (int i = 0; i < 8; i++)
  24.                 {
  25.                     napis[i] = (char)rnd.Next(48, 122);
  26.                     if ((napis[i] > 57 && napis[i] < 65) || (napis[i] > 90 && napis[i] < 97))
  27.                     {
  28.                         napis[i] = (char)rnd.Next(48, 122);
  29.                         i--;
  30.                     }
  31.                 }
  32.                 for(int j = 0; j < 8; j++)
  33.                 {
  34.                     if ((napis[j] >= 65 && napis[j] <= 90) || (napis[j] >= 97 && napis[j] <= 122)) litera++;
  35.                 }
  36.             } while(litera!=4);
  37.            
  38.             foreach (char i in napis) Console.Write("{0}", i);
  39.             Console.WriteLine();
  40.  
  41.             //ZADANIE 2.
  42.             //a) Czy podany napis zawiera podciąg złożony kolejno z 3 liter i 2 cyfr.
  43.             /*
  44.             String napisB;
  45.             napisB = String.Join("", napis);
  46.             if (Regex.IsMatch(napisB, "[0-9]{2}-[0-9]{3} [A-Z]{1}[a-z]*")) Console.WriteLine("True");
  47.             */
  48.             //ZADANIE 3.
  49.             //Dla dowolnego napisu spradzić czy jest on poprawnym adresem 21-500 Biała Podlaska.
  50.  
  51.             string adres;
  52.             Regex regA = new Regex(@"[0-9]{2}-[0-9]{3} [A-Z]{1}[a-z]*");
  53.             Regex regB = new Regex(@"[0-9]{2}-[0-9]{3} [A-Z]{1}[a-z]* [A-Z]{1}[a-z]*");
  54.  
  55.             //adres = Console.ReadLine();
  56.             adres = "21-500 Biała Podlaska";
  57.             if(regA.IsMatch(adres) || regB.IsMatch(adres)) Console.WriteLine("Podany adres jest prawidłowy!");
  58.             else Console.WriteLine("Podany adres jest nieprawidłowy!");
  59.             Console.ReadLine();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement