Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace FancyBarcodes
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfLines = int.Parse(Console.ReadLine());
- Regex regexForBarcode = new Regex(@"@#+[A-Z][A-Za-z0-9]{4,}[A-Z]@#+");
- Regex regexForDigits = new Regex(@"[0-9]");
- for (int i = 0; i < numberOfLines; i++)
- {
- string barcodeInput = Console.ReadLine();
- Match matchValidBarcode = regexForBarcode.Match(barcodeInput);
- MatchCollection matchesDigits = regexForDigits.Matches(barcodeInput);
- if (matchValidBarcode.Success)
- {
- string productGroup = "00";
- if (regexForDigits.IsMatch(barcodeInput))
- {
- productGroup = string.Empty;
- foreach (Match matches in matchesDigits)
- {
- productGroup += matches.Value;
- }
- }
- Console.WriteLine($"Product group: {productGroup}");
- }
- else
- {
- Console.WriteLine("Invalid barcode");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement