Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace _2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Regex regex = new Regex(@"@#+([A-Z]{1}[a-z,A-Z,0-9]{4,}[A-Z]{1})@#+");
- int times = int.Parse(Console.ReadLine());
- for (int i = 0; i < times; i++)
- {
- var inputBarcode = Console.ReadLine();
- Match match = regex.Match(inputBarcode);
- if (match.Success)
- {
- var validBarcode = match.Groups[1].Value;
- var groupCode = GetBarcodeGroup(validBarcode);
- Console.WriteLine($"Product group: {groupCode}");
- }
- else
- {
- Console.WriteLine("Invalid barcode");
- }
- }
- }
- public static string GetBarcodeGroup(string barcode)
- {
- var groupCode = string.Empty;
- foreach (var letter in barcode)
- {
- if (char.IsNumber(letter))
- groupCode += letter;
- }
- if (groupCode == "")
- groupCode = "00";
- return groupCode;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement