Advertisement
silvana1303

fancy barcodes

Aug 5th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace _02._Boss_Rush
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Regex regex = new Regex(@"^[@][#]+(?<barcode>[A-Z][a-zA-Z0-9]{4,}[A-Z])[@][#]+$");
  14.  
  15.             int times = int.Parse(Console.ReadLine());
  16.  
  17.             //Dictionary<string, string> items = new Dictionary<string, string>();
  18.  
  19.            
  20.  
  21.             for (int i = 0; i < times; i++)
  22.             {
  23.                 string input = Console.ReadLine();
  24.  
  25.                 Match match = regex.Match(input);
  26.  
  27.                 string sticker = "";
  28.  
  29.                 if (match.Success)
  30.                 {
  31.                     string barcode = match.Groups["barcode"].Value;
  32.  
  33.                     Regex digit = new Regex(@"[0-9]");
  34.  
  35.                     MatchCollection number = digit.Matches(barcode);
  36.  
  37.                     foreach (Match item in number)
  38.                     {
  39.                         //items[barcode] += item;
  40.                         sticker += item.Value;
  41.                     }
  42.  
  43.                     if (number.Count == 0)
  44.                     {
  45.                         // items[barcode] = "00";
  46.                         sticker = "00";
  47.                     }
  48.  
  49.                     Console.WriteLine($"Product group: {sticker}");
  50.                 }
  51.                 else
  52.                 {
  53.                     Console.WriteLine("Invalid barcode");
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement