Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _04_CubicwithRegex
- {
- class Program
- {
- static void Main(string[] args)
- {
- var pattrern = @"(\d+)([a-zA-Z]+)(\W|[0-9]+)";
- var regex = new Regex(pattrern);
- while (true)
- {
- var input = Console.ReadLine();
- if (input == "Over!")
- {
- break;
- }
- var number = int.Parse(Console.ReadLine());
- var matches = regex.Match(input);
- if (matches.Length != input.Length)
- {
- continue;
- }
- var firstMatch = matches.Groups[1].Value;
- var text = matches.Groups[2].Value;
- var lastMatch = matches.Groups[3].Value;
- var digits = "";
- foreach (var character in firstMatch)
- {
- var num = int.Parse(character.ToString());
- digits += num;
- }
- foreach (var character in lastMatch)
- {
- var num = -1;
- if (int.TryParse(character.ToString(), out num))
- {
- digits += num;
- }
- }
- var verificationCode = "";
- foreach (var index in digits)
- {
- var digit = int.Parse(index.ToString());
- if (digit < text.Length)
- {
- verificationCode += text[digit];
- }
- else
- {
- verificationCode += " ";
- }
- }
- Console.WriteLine($"{text} == {verificationCode}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment