Guest User

Untitled

a guest
Jul 21st, 2022
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace P02.FancyBarcodes
  6. {
  7.     internal class FancyBarcodes
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string barcodePattern = @"^@#+([A-Z][A-Za-z0-9]{4,}[A-z])@#+$";
  12.  
  13.             int countOfBarcodes = int.Parse(Console.ReadLine());
  14.  
  15.             for (int i = 0; i < countOfBarcodes; i++)
  16.             {
  17.                 string barcode = Console.ReadLine();
  18.  
  19.                 Match match = Regex.Match(barcode, barcodePattern);
  20.  
  21.                 if (match.Success)
  22.                 {
  23.                     if (match.Value.Any(s => char.IsDigit(s)))
  24.                     {
  25.                         string productGroup = string.Join("", match.Value.Where(s => char.IsDigit(s)));
  26.  
  27.                         Console.WriteLine($"Product group: {productGroup}");
  28.                     }
  29.                     else
  30.                     {
  31.                         Console.WriteLine("Product group: 00");
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.WriteLine("Invalid barcode");
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment