I've written a simple program for finding the smallest permutation of a string
which is lexicographically larger than the current one. But, the compiler emits the error
ERROR CS1003 Syntax error, ':' expected* ".
I use VS 2015 (update 3) and whenever I compile this program (which seems to be grammatically true), I encounter the aforementioned error.
Does this program have any error in syntax?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
const string a = "ABCDEFG";
//var u = FFG(a);
//var t = int.Parse(Console.ReadLine());
//for (int i = 0; i < t; i++)
//{
// Console.WriteLine(FFG(Console.ReadLine()));
//}
string u2 = a;
string u = a;
do
{
//***The follownig line meets Error***
Console.WriteLine(u + $"{String.Compare(u, u2) > 0 ? true:false}");
} while ((u = FFG(u)) != "no answer");
Console.ReadLine();
}
static string FFG(string ss)
{
var s = ss.ToCharArray();
int i = s.Length - 1;
while (i >= 1 && s[i] <= s[(i--) - 1])
{ }
if (i == 0 && s[0] >= s[1])
return "no answer";
int j = s.Length - 1;
while (s[i] >= s[(j--)])
{ }
j++;
swap(s, i, j);
int t = i + 1, tt = s.Length - 1;
if (j - i >= 2)
while (t < tt)
{
//if (t == j)
// t++;
//if (tt == j)
// tt--;
swap(s, t, tt);
t++; tt--;
}
return new string(s);
}
static void swap<T>(T[] array, int i, int j)
{
T k = array[i];
array[i] = array[j]; array[j] = k;
}
}