Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
1,900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4.  
  5. namespace Problem_2._Fancy_Barcodes
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var regex = new Regex(@"^@#+(?<barcode>[A-Z][A-Za-z0-9]{4,}[A-Z])@#+$");
  12. var digitRegex = new Regex(@"\d");
  13.  
  14. int n = int.Parse(Console.ReadLine());
  15. for (int i = 0; i < n; i++)
  16. {
  17. string input = Console.ReadLine();
  18. var match = regex.Match(input);
  19. if (match.Success)
  20. {
  21. string name = match.Groups["barcode"].Value;
  22. var digitMatch = digitRegex.Matches(name);
  23. string productGroup = string.Empty;
  24.  
  25. foreach (Match digit in digitMatch)
  26. {
  27. if (digit.Success)
  28. {
  29. productGroup += digit.Value;
  30. }
  31. }
  32. if (productGroup.Length == 0)
  33. {
  34. productGroup = "00";
  35. }
  36.  
  37. Console.WriteLine($"Product group: {productGroup}");
  38. }
  39. else
  40. {
  41. Console.WriteLine("Invalid barcode");
  42. }
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement