Advertisement
Guest User

Untitled

a guest
Dec 4th, 2020
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace ExamPrep_02_FancyBarcodes
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int count = int.Parse(Console.ReadLine());
  11.  
  12.             string pattern = @"(@#+)([A-Z][A-Za-z0-9]{4,}[A-Z])\1";
  13.             Regex barcodeRegex = new Regex(pattern);
  14.  
  15.             while (count-- > 0)
  16.             {
  17.                 string input = Console.ReadLine();
  18.                 Match match = Regex.Match(input, pattern);
  19.  
  20.                 if (match.Success)
  21.                 {
  22.                     string productGroup = "";
  23.  
  24.                     for (int i = 0; i < match.Value.Length; i++)
  25.                     {
  26.                         if (char.IsDigit(match.Value[i]))
  27.                         {
  28.                             productGroup += match.Value[i];
  29.                         }
  30.                     }
  31.  
  32.                     if (productGroup != "")
  33.                     {
  34.                         Console.WriteLine($"Product group: {productGroup}");
  35.                     }
  36.                     else
  37.                     {
  38.                         Console.WriteLine($"Product group: 00");
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     Console.WriteLine("Invalid barcode");
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement