110,533
社区成员
发帖
与我相关
我的任务
分享
class Test
{
static void Main()
{
string input = "你是泊于青春的港口的一叶小舟!愿你扬起信念的帆,载着希望的梦幻,驶向辽阔的海洋。";
foreach (var s in Permute(input))
{
// show s
}
}
public static IEnumerable<string> Permute(string line)
{
char[] chars = line.ToCharArray();
var indice = chars.Select((c, i) => new { C = c, I = i })
.Where(x => Punctuations.Contains(x.C))
.ToList();
int count = 1 << indice.Count;
for (int i = 0; i < count; i++)
{
for(int j = 0; j<indice.Count; j++)
{
chars[indice[j].I] = indice[j].C;
if (((1 << j) & i) != 0)
{
chars[indice[j].I] = ChangeCase(indice[j].C);
}
}
yield return new string(chars);
}
}
static string Punctuations = "!!,,";
static char ChangeCase(char c)
{
int i = Punctuations.IndexOf(c);
return Punctuations[i + (i % 2 == 0 ? 1 : -1)];
}
}