-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
36 lines (35 loc) · 1019 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Text;
namespace PerformStringShifts
{
class Program
{
static void Main(string[] args)
{
string s = "abc";
int[][] shift = new int[2][];
shift[0] = new int[] {0, 1};
shift[1] = new int[] {1, 2};
Console.WriteLine(StringShift(s, shift));
}
static string StringShift(string s, int[][] shift)
{
var str = new StringBuilder(s);
foreach (var move in shift)
{
move[1] %= s.Length;
if (move[0] == 0)
{
str.Append(str.ToString().Substring(0, move[1]));
str.Remove(0, move[1]);
}
else
{
str.Insert(0, str.ToString().Substring(str.Length - move[1]));
str.Remove(str.Length - move[1], move[1]);
}
}
return str.ToString();
}
}
}