Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Linq;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- string[] keys = Console.ReadLine().ToUpper().Split('&');
- Regex pattern = new Regex(@"^[A-Z\d]{25}|[A-Z\d]{16}$");
- List<string> result = new List<string>();
- foreach (var k in keys)
- {
- if (pattern.IsMatch(k))
- {
- char[] chars = k.ToCharArray();
- for (int i = 0; i < chars.Length; i++)
- {
- if (char.IsDigit(chars[i]))
- {
- chars[i] = (char)('9' - (chars[i] - '0'));
- }
- }
- string key = string.Join("", chars);
- if (key.Length == 25)
- {
- result.Add(key.Substring(0, 5) + "-" + key.Substring(5, 5) + "-" +
- key.Substring(10, 5) + "-" + key.Substring(15, 5) + "-" +
- key.Substring(20, 5));
- }
- else
- {
- result.Add(key.Substring(0, 4) + "-" + key.Substring(4, 4) + "-" +
- key.Substring(8, 4) + "-" + key.Substring(12, 4));
- }
- }
- }
- Console.WriteLine(string.Join(", ", result));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement