Вывести буквы английского алфавита в заданной последовательности - C#
Формулировка задачи:
Подскажите, как реализовать алгоритм, чтобы печатались буквы английского алфавита и разбивались на слова в такой последовательности: z yz xyz wxyz ... abcdefghijklmnopqrstuvwxyz
И чтобы их можно было использовать для поиска в других строках.
Решение задачи: «Вывести буквы английского алфавита в заданной последовательности»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace zyz
{
class Program
{
static void Main(string[] args)
{
var input = Console.ReadLine() ?? "";
var words = GetAlphabetPostfixes();
PrintWordsPositions(words, input);
}
private static void PrintWordsPositions(List<string> words, string input)
{
foreach (var word in words)
{
var indexes = new List<int>();
foreach (Match match in Regex.Matches(input, word))
{
indexes.Add(match.Index);
}
if (indexes.Count > 0)
Console.WriteLine($"Substring {word} found at positions: {string.Join(" ", indexes)}");
}
}
private static List<string> GetAlphabetPostfixes()
{
var words = new List<string> {"z"};
for (char ch = 'y'; ch >= 'a'; --ch)
{
words.Add(ch + words.Last());
}
return words;
}
}
}