Untitled
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
using System; using System.Collections.Generic; class CaesarCipherWithSubstrings { static string CaesarShift(string str, int shift) { char[] charArray = str.ToCharArray(); for (int i = 0; i < charArray.Length; i++) { if (char.IsLetter(charArray[i])) { char baseChar = char.IsUpper(charArray[i]) ? 'A' : 'a'; charArray[i] = (char)(((charArray[i] - baseChar + shift) % 26 + 26) % 26 + baseChar); } } return new string(charArray); } static string Solve(string s, List<Tuple<int, int, int>> operations) { char[] result = s.ToCharArray(); foreach (var operation in operations) { int start = operation.Item1; int end = operation.Item2; int shift = operation.Item3; for (int i = start; i <= end; i++) { if (char.IsLetter(s[i])) { result[i] = CaesarShift(result[i].ToString(), shift)[0]; } } } return new string(result); } static void Main(string[] args) { string s = "abcdefg"; List<Tuple<int, int, int>> operations = new List<Tuple<int, int, int>>() { Tuple.Create(1, 3, 2), Tuple.Create(4, 5, 1) }; string result = Solve(s, operations); Console.WriteLine(result); // Output: "abdgfg" } }